0
#!/bin/bash

for arg
do
        echo "$arg"
done

In file called compile.

I tried this:

compile ha -aa -bb -cc -dd -ee -ff -gg
ha
-aa
-bb
-cc
-dd

-ff
-gg

Why does -ee not show up? In fact, it seems that -[e]+ does not show up.

2 Answers 2

4

Because the version of echo you use takes -e as an option (meaning "expand escape characters").

Edited to add:

The standard response to this type of question is "use printf", which is strictly accurate but somewhat unsatisfactory. printf is a lot more annoying to use because of the way it handles multiple arguments. Thus:

$ echo -e a b c
a b c
$ printf "%s\n" -e a b c
-e
a
b
c
$ printf "%s" -e a b c
-eabc$ # That's not what I wanted either

Of course, you just need to remember to quote the entire argument sequence, but that can lead to annoying quote-escaping issues.

Consequently, I offer for your echoing pleasure:

$ ech-o() { printf "%s\n" "$*"; }
$ ech-o -e a b c
-e a b c
$
Sign up to request clarification or add additional context in comments.

Comments

1

Here it says that it's not possible with GNU echo but you could use printf.

for arg
do
    printf "%s\n" "$arg"
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.