Question

echo "Hello" > $XYZ

echo ${?}

If I copy paste those two lines in any .sh file the scripts are working fine without any issues. ${?} in the second line is returning 0. $XYZ can be replaced with any random string. The variable need not be defined or initialized.

However, the same code is not working for some users. The first line is throwing the error "scriptname.sh[425]: : cannot open".

${?} in the second line is returning 1.

Any idea on why the same piece of code is giving different results for different users?

Note: We are facing this issue in the server "IBM/AIX RISC System/6000"

No correct solution

OTHER TIPS

The variable XYZ needs to hold a non-empty string in order for the shell to be able to parse the redirection. Maybe initialize it to /dev/null if you want it to default to no result at all (which is what I imagine you might expect a redirection to nothing to accomplish; but it doesn't).

Make sure to write the assignment statement of XYZ in the correct form. e.g:

XYZ="fileName"
echo "Hello" > $XYZ
...

XYZ="fileName" is without spaces.. I don't know but this is the only issue that came to my mind

I would imagining the log file ($XYZ) is not accessible to different users in AIX, try giving 755 to log file directory and also make sure your file having enough permissions to get executed by others (755 again)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top