hi,
i want to check whether a a variable contains some value or is empty in a shell script. so if the variable contains some value i want to do some job and if the variable doesnt contain any value then i need to skip that job.
here is a sample script
read_filenames.sh contains
FILENAME=$1
FILE="s1.txt"
if [ -n $FILENAME ]; then
FILE=$FILENAME
fi
echo "FILE = {$FILE}"
so, when i run the script without passing any argument, variable "FILE" should contain "s1.txt". so the output should be
$ sh read_filenames.sh
FILE = {s1.txt}
but when i pass an argument to the script, then the variable "FILE" should contain the argument value. so the output should be
$ sh read_filenames.sh p1.txt
FILE = {p1.txt}
currently i am using the above code, but if i dnt pass any argument to the script. the output is
FILE = {}
i read somewhere that
if [ -n $FILENAME ]; then
checks whether the variable is empty or not. but i dnt think that its doing that job. can anyone tell how can i do the above.