Hi I have a question about bash.
and I'm new to it.
I made a file named "test.sh" and its contents is
#!/bin/bash
set -x
echo $UID
echo "$UID"
echo "$(id -u)"
and the result is blank!! nothing shows up
However, when i just type "echo $UID" on terminal it shows "1011"
is there anything i missed for bash?
Please help
UPDATED
bash version is 4.3.11 and I typed "sh test.sh" to execute.
and the result is
+ echo
+ echo
+ id -u
+ echo 1011
1011
thanks!
Symbol: $# The symbol $# is used to retrieve the length or the number of arguments passed via the command line. When the symbol $@ or simply $1, $2, etc., is used, we ask for command-line input and store their values in a variable.
The dollar sign before the thing in parenthesis usually refers to a variable. This means that this command is either passing an argument to that variable from a bash script or is getting the value of that variable for something.
$2 is the second command-line argument passed to the shell script or function. Also, know as Positional parameters.
$UID
is a Bash variable that is not set under sh
, that may be why it outputs blank lines.
Try bash test.sh
or make your script executable with chmod u+x test.sh
, the program defined in shebang will then be used (/bin/bash
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With