1

I have the following code snippet:

#!/bin/sh 

if [ $1 = hi ]; then 
    echo 'The first argument was "hi"'
else
    echo -n 'The first argument was not "hi" -- ' 
    echo It was '"'$1'"'
fi

And I don't know what the flag -n after echo in the else statement stands for, does anyone knows the answer?

Thank you very much!

almrog
  • 21
  • 1
  • 2
  • 2
    Try looking at the man page for echo. It's a fairly straight forward flag – hakskel Apr 12 '20 at 21:01
  • 5
    @hakskel ... depending on the shell `echo` might be a built-in (e.g. in Bash, Zsh). So while there may be a `man`-page for `/bin/echo` or so, `help echo` would be the way to go in that case (i.e. Bash only). And `type echo` can be used to find out which one your shell uses (built-in or command etc ..., i.e. in both Bash and Zsh again). – 0xC0000022L Apr 12 '20 at 21:16
  • http://www.man7.org/linux/man-pages/man1/echo.1.html – BlueManCZ Apr 12 '20 at 21:20
  • 3
    Welcome on U&L! You'll find various relevant details in [Why is printf better than echo?](https://unix.stackexchange.com/q/65803/315749). – fra-san Apr 12 '20 at 21:47
  • 1
    Another option is to experiment and see if you observe any difference. Try (1) `echo hi` and (2) `echo -n hi`. Does `echo -n` behave differently? – Andy Dalton Apr 12 '20 at 23:08

1 Answers1

4

The traditional way to learn about the options and parameters of a un*x command is by using the man (manual) command, e.g.

man echo

If you issue that on your system, you should see a description of the echo command including something like

Echo the STRING(s) to standard output.

-n do not output the trailing newline

user4556274
  • 8,725
  • 2
  • 31
  • 37