Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Just Joined!
    Join Date
    Feb 2007
    Posts
    4

    The FIx

    I just had to change x to e

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    But do you know why that made it work?

  4. #4
    Just 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.

  5. #5
    scm
    scm is offline
    Linux 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...