0

I have two questions:

1.When I read some bash scripts, I found a way to iterate all the options passed to the current script:

for option
do
    echo $option
done

However, I know little about what "option" is in bash. Can anyone give me some references about that? Thanks.

2.Just as above, when I passed "-e" or "-n" options to my script, "echo" can't print them as a string because "echo" treats them as options! How to make "echo" print "-e" and "-n" as content strings?

nicky_zs
  • 3,483
  • 1
  • 17
  • 25

3 Answers3

2
  1. option is just an arbitrary variable name. The for command will assign it to each argument as it iterates.

  2. Use printf instead of echo:


for arg
do
    printf "%s" "$arg"
done
Barmar
  • 669,327
  • 51
  • 454
  • 560
0

To answer the 2nd part of the question, the general solution is to use printf instead of echo. See How do I echo "-e"?

Community
  • 1
  • 1
Digital Trauma
  • 14,662
  • 2
  • 46
  • 78
0

1 option is a variable. You could have called it i

for i
do
  echo "$i"
done

2 echo You could use

echo "-e -n hi"
-e -n hi
Elliott Frisch
  • 191,680
  • 20
  • 149
  • 239