Results 1 to 5 of 5
#!/bin/sh
################################################## ###########################################
###### Brandon Sabean ########################################
###### July 23, 2007 ########################################
###### ########################################
###### script for FretsOnFire to make sure theres a ########################################
###### song.ogg. If it already exists ...
- 07-24-2007 #1Just Joined!
- Join Date
- Feb 2007
- Posts
- 4
Bash shell help
#!/bin/sh
################################################## ###########################################
###### Brandon Sabean ########################################
###### July 23, 2007 ########################################
###### ########################################
###### script for FretsOnFire to make sure theres a ########################################
###### song.ogg. If it already exists it will not ########################################
###### overwrite. ########################################
################################################## ###########################################
i=0; #Counter for the number of files
for dir in /home/king/Games/FretsOnFire/data/songs/*/; do
#echo $dir
cd "$dir"
file=song.ogg
echo $i
echo "if [ -x "$dir""$file" ] then"
if [ -x "$file" ]; then
echo "File Exists"
else
echo "The file doesnt exist"
echo $dir
cp -f "$dir"guitar.ogg "$dir"song.ogg
cd ..
fi
let i=i+1
done
echo "Done"
basically this works but when you run it the second time only some of the file say they exist, What is going on is there is spaces and other escape characters when it goes into the test, What I need to know is how to make the file exists to recognize them so it sees that the file actually exists.
- 07-24-2007 #2Just Joined!
- Join Date
- Feb 2007
- Posts
- 4
The FIx
I just had to change x to e
- 07-24-2007 #3Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
But do you know why that made it work?
- 07-25-2007 #4Just Joined!
- Join Date
- Feb 2007
- Posts
- 4
Yes
I do know why it works and the other doesnt. x checks for executables and e checks to see if the file exists doesnt care if its an executable.
- 07-25-2007 #5Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
But do you know why it could find files the first time, but not the second when you were checking them for being executable? IMO you should thoroughly understand why a solution works to avoid being bitten by a similar one in the future - especially important when you're just starting out.


Reply With Quote