0

I have a tiny question. When I execute my shell file by 'sh', it works differently. (it printed '-e')

Google says "Check your first line(#!/bin/bash) and 'env | grep sh'" But there no do difference in my eyes... Would you tell me why it is?

+++ I tried changing '#!/bin/bash' → '#!/bin/dash', but noting changed.

Thanks for reading..

[my first code(first.sh)] -bash

#!/bin/bash
echo -e "hi"

[run script and result]

# . first.sh
Hi
# source first.sh
Hi
# sh first.sh
-e hi

[my second code(second.sh)] -dash

#!/bin/dash
echo -e "hi"

[run script and result] nothing change...

[OS] ubuntu 18.04

[environment]

# env | grep sh
SHELL=/bin/bash
# ll /bin | grep sh
-rwxr-xr-x  1 root root 1113504  6월  6  2019 bash*
-rwxr-xr-x  1 root root  121432  1월 25  2018 dash*
lrwxrwxrwx  1 root root       4  6월  6  2019 rbash -> bash*
lrwxrwxrwx  1 root root       4  7월 18  2019 sh -> dash*
lrwxrwxrwx  1 root root       4  7월 18  2019 sh.distrib -> dash*
helpMe
  • 9
  • 3

1 Answers1

0

that is because the sh shell interpreter does not recognize -e as a flag and prints it as a regular string.

source and . use your SHELL env, which is bash, whom recognizes the -e flag and does not treat it as a string.

Nahuel
  • 158
  • 8