shell - Substituting command echo with "echo -e" on linux -
i have shell program has content this
!#/bin/bash echo \\n program once run program on platform other linux recognizes special character , gives output as
(newline) program when same program runs on linux, echo command needs "-e" option. don't want change each occurrence of echo "echo -e" in file explicitly because start creating issues on other platforms. want conditional compilation
set system="uname -s" #if ($system == linux) set echo="echo -e" #endif but not work because using set or export command, need replace occurrences of echo $echo, don't want do. again setting aliases not solve issue need echo replaced "echo -e" in subshell.
is there other way around can substitute echo "echo -e" linux platform?
using combination of bash_env , function can do:
bash-3.2$ export bash_env=$home/always-source bash-3.2$ cat $home/always-source echo() { command echo -e "$@" } bash-3.2$ cat runme.bash #!/bin/bash echo "\nhello world $1\n" if [[ -z $1 ]]; $0 child fi and invocation:
bash-3.2$ ./runme.bash hello world hello world child wrapping in bash test (linux & mac os x):
if [[ $(uname -s) = linux ]] || [[ $(uname -s) = darwin ]]; export bash_env=$home/always-source fi
Comments
Post a Comment