0

Can anyone explain what's going on with DR here?

user@host:~# DRYRUN=true
user@host:~# echo "$DRYRUN"
true
user@host:~# $DRYRUN && export DR="-n"
user@host:~# echo $DR
user@host:~# $DRYRUN && export DR="-n" && echo $DR
user@host:~# $DRYRUN && export DR="-n" && echo "$DRYRUN --- $DR"
true --- -n
user@host:~# echo $DR
user@host:~# echo "$DRYRUN --- $DR"
true --- -n
user@host:~#

I Just want to assign DR to the string "-n" when DRYRUN is set to true but what I'm getting is confusing

0

1 Answer 1

4

The value of DR (-n) is being interpreted as an option for echo. Specifically:

-n do not output the trailing newline

You should use printf instead:

printf '%s\n' "$DR"

Alternatively, you can add something so the -n isn't the first thing echo sees:

echo "DR: $DR"
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.