BASH - getting UID on shell script not working

Hi, I have a question about bash.

and I'm new to this.

I created a file called "test.sh" and its contents

#!/bin/bash
set -x
echo $UID
echo "$UID"
echo "$(id -u)"

and the result is empty! nothing is displayed

However, when I just type "echo $ UID" on the terminal it shows "1011"

is there anything i missed for bash?

Please, help

UPDATED

bash version 4.3.11, and I typed "sh test.sh" to execute.

and result

+ echo

+ echo

+ id -u
+ echo 1011
1011

thank!

+4
source share
1 answer

$UIDis a Bash variable that is not set to sh, so empty lines may be output.

bash test.sh script chmod u+x test.sh, , shebang (/bin/bash)

+2

Source: https://habr.com/ru/post/1654321/


All Articles