1

I'm in the process of porting over another shell script when I came across the following:

if [[ ! -x $DVDREC ]]; then
  print "ERROR: $DVDREC not found. Exiting ..."
  exit 1
fi

if [[ ! -c ${DVDDEV} ]]; then
  print "ERROR: ${DVDDEV} not found. Exiting ..."
  exit 1
fi

I was wondering what the -c and -x options actually do with regards to the strings stored in DVDREC and DVDDEV?

j0k
  • 22,600
  • 28
  • 79
  • 90
Justin
  • 742
  • 5
  • 17
  • 34

3 Answers3

3

From "help test" in a bash shell:

  -c FILE        True if file is character special.
  -x FILE        True if the file is executable by you.
jordanm
  • 33,009
  • 7
  • 61
  • 76
3

// man test

   -c FILE
          FILE exists and is character special

   -x FILE
          FILE exists and execute (or search) permission is granted
rush
  • 2,484
  • 2
  • 19
  • 31
3

Citing man test:

   -c FILE
          FILE exists and is character special

   -x FILE
          FILE exists and execute (or search) permission is granted
vitaut
  • 49,672
  • 25
  • 199
  • 336
  • Thanks for your help. I'm fairly new to the Linux Operating System so I wasn't aware that there was a manpage for test. – Justin Jul 03 '12 at 15:19
  • 1
    @Justin: No problems. For people who are new to bash the relationship between `[` and `test` is not obvious. So it's a good question. – vitaut Jul 03 '12 at 15:26
  • 1
    @justin - the manpage isn't for the test command that you would be using. The `test` builtin or `[` would be used first. In your case, you are using a bash keyword `[[`, rather than a command. The flags are the same. – jordanm Jul 03 '12 at 15:27