You need to understand how Unix interprets your input.
The standard Unix shell interpolates environment variables and what are called globes before passing parameters to your program. This is slightly different from Windows, which causes the program to interpret the extension.
Try the following:
$ echo *
This will reflect all files and directories in your current directory. Before the echo command acts, the shell interpolates * and extends it, then passes that extended parameter back to your command. You can see this in action by doing the following:
$ set -xv $ echo * $ set +xv
set -xv -xv includes xxtrace and verbose. Verbose repeats the command entered, and the xtrace echos command to be executed (that is, after the shell extension).
Now try the following:
$ echo "*"
Note that putting something inside quotation marks hides the glob expression from the shell, and the shell cannot expand it. Try the following:
$ foo="this is the value of foo" $ echo $foo $ echo "$foo" $ echo '$foo'
Note that the shell can still extend environment variables inside double quotes, but not in single quotes.
Now look at your statement:
file="home/edward/bank1/fiche/Test*"
Double quotes do not allow the shell to expand the glob expression, so file is equal to the letter home/edward/bank1/finche/Test* . So you need to do this:
file=/home/edward/bank1/fiche/Test*
The absence of quotation marks (and the introductory line, which is important!) Will now make the file equal to all the files that match this expression. (There may be more than one!). If there are no files, depending on the shell and its settings, the shell can simply install the file on this literal line anyway.
You probably have the right idea:
file=/home/edward/bank1/fiche/Test* if test -s $file then echo "found one" else echo "found none" fi
However, you can still find not found if there is more than one file. Instead, you may receive an error message in your test command because there are too many parameters.
One way around this could be:
if ls /home/edward/bank1/finche/Test* > /dev/null 2>&1 then echo "There is at least one match (maybe more)!" else echo "No files found" fi
In this case, I use the ls exit code. If ls finds one file to which it has access, it returns a zero exit code. If it cannot find one suitable file, it returns a non-zero exit code. The if command simply executes the command, and then if the command returns zero, it accepts the if as true and executes the if clause. If the command returns a nonzero value, the if is considered false, and the else clause is executed (if available).
The test command works in a similar way. If test true, test returns zero. Otherwise, the test command returns a nonzero value. This works great with the if command. Actually there is an alias of the test command. Try the following:
$ ls -li /bin/test /bin/[
i prints the inode. The indent is the real file identifier. Files with the same identifier are the same file. You can see that /bin/test and /bin/[ are the same command. This makes the following two commands the same:
if test -s $file then echo "The file exists" fi if [ -s $file ] then echo "The file exists" fi