简体   繁体   中英

How do I reconfigure my Mac to get bash script to use echo like it used to?

Not a Mac guy here.

Many months ago I wrote the following command in a bash script on a Mac.

export AUTH=$(echo -n "$USER_ID:$SVC_KEY" | base64)

It worked as you would expect, the base64 of "value_of_USER_ID:value_of_SVC_KEY". Months later I run it and the output is the base64 of "-n value_of_USER_ID:value_of_SVC_KEY".

InB4 yes, it took me a while to figure out that this was the problem :-)

What setting changed to cause the "-n " to be included? How do I change it back?

Thanks!

It sounds like you may have changed your shell from bash to sh . In sh the way to echo without a newline is to end it with \\c :

export AUTH=$(echo "$USER_ID:$SVC_KEY\c" | base64)

But a more portable way to print without a newline is to use printf :

export AUTH=$(printf "%s" "$USER_ID:$SVC_KEY" | base64)

See 'echo' without newline in a shell script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM