test statement in bash
I initialized the todays_CASH_session to null and hope that if the variable after the for loop was still null that it would go to the last stetement for user to check the engine.
is the test -n the right tool to use, when i run the command raw from the terminal i get nothing. (/data/execCmd flight05 /RASH/STATUS | grep Session | cut -d" " -f2 | sort -u so it should be null in script after for loop. but the script is acting line it has a value. Code:
#!/bin/sh |
do i need the exit statement at the end of the if statments ?
|
You only need an exit statement at the end of the script.
|
When you set todays_CASH_session, the loop runs from i=0 while i < 1, so you will always execute the value setting once.
That is, this section: Code:
todays_CASH_session='' Code:
todays_CASH_session=$(/data/execCmd light05 /CASH/STATUS | grep Session | cut -d" " -f2 | sort -u) Can't you just run the command in a terminal window and look at the output? |
I was hoping if the -- /data/execCmd light05 /CASH/STATUS | grep Session | cut -d" " -f2 | sort -u -- returned no value the program would skip to bottom -- echo "Please check to see that engine is running". However even when i run it from the command line and get nothing back, i run the script and the internal if statements are run.
I do not know if -n is the right tool for the job. |
Yeah so I am not asking why the todays_CASH-session returns an null string. my concern is that when the return values is nothing, the assignment is null, why are the nested if statments running.
is -n the right tool for testing the statement. are the if statements nested wrong. becasue it the todays_CASH_session is null, it should jump to bottom of program |
Quote:
Code:
[ -n session ] Code:
if [ -n "$todays_CASH_session" ]; then |
DEAD_ON_TARGET
quoting the variable - thanks. |
Is there any special reason why you're using #!/bin/sh here? If you don't need posix-compliant portability, then you should probably switch it to /bin/bash and take advantage of its more advanced features, such as the [[ test.
http://mywiki.wooledge.org/BashFAQ/031 And as you've discovered, you should always quote your variable and expansions and command substitutions, unless you want word-splitting to occur. http://mywiki.wooledge.org/Arguments http://mywiki.wooledge.org/WordSplitting http://mywiki.wooledge.org/Quotes This is particularly important inside the old [ test (but not [[, see the link for details). |
All times are GMT -5. The time now is 12:55 AM. |