Find the answer to your Linux question:
Results 1 to 2 of 2
I'm trying to use this script, but it's not working: Code: ubuntu@ubuntu:~/Desktop$ cat ./script.sh #!/bin/sh if [ -e ./000[0-9].cat ] then echo "meow" else echo "woof" fi ubuntu@ubuntu:~/Desktop$ bash -x ...
  1. #1
    Linux User Agent-X's Avatar
    Join Date
    May 2005
    Location
    Dimension X
    Posts
    261

    metacharacters and if-then statements

    I'm trying to use this script, but it's not working:

    Code:
    ubuntu@ubuntu:~/Desktop$ cat ./script.sh 
    #!/bin/sh
    if [ -e ./000[0-9].cat ]
    then
    echo "meow"
    else
    echo "woof"
    fi
    ubuntu@ubuntu:~/Desktop$ bash -x ./script.sh 
    + '[' -e ./0000.cat ./0001.cat ./0009.cat ']'
    ./script.sh: line 2: [: too many arguments
    + echo woof
    woof
    Is there a proper way to do this?
    I have files 0000.cat 0001.cat 0009.cat and 0010.cat

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    go through every .cat file
    Code:
    for F in *cat
    do
     case $F in
        000[0-9]* ) echo "meow" ;;
        * ) echo "sdfs";;
      esac
    done

Posting Permissions

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