Skip to content

Commit 6f5af8b

Browse files
authored
Replace echo -e with printf for bash 3.2 (mac) (#41)
1 parent 910602d commit 6f5af8b

File tree

38 files changed

+580
-538
lines changed

38 files changed

+580
-538
lines changed

Runfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def examples
3030
"examples/config-ini/configly",
3131
"examples/custom-includes/download",
3232
"examples/custom-strings/download",
33+
"examples/default-command/ftp",
3334
"examples/dependencies/cli",
3435
"examples/docker-like/docker",
3536
"examples/environment-variables/cli",

examples/colors/colorly

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,34 @@ version_command() {
2323
# :command.usage
2424
colorly_usage() {
2525
if [[ -n $long_usage ]]; then
26-
echo -e "colorly - Sample application that uses the color functions"
26+
printf "colorly - Sample application that uses the color functions\n"
2727
echo
2828
else
29-
echo -e "colorly - Sample application that uses the color functions"
29+
printf "colorly - Sample application that uses the color functions\n"
3030
echo
3131
fi
32-
echo -e "Usage:"
33-
echo -e " colorly [MESSAGE] [options]"
34-
echo -e " colorly --help | -h"
35-
echo -e " colorly --version"
32+
printf "Usage:\n"
33+
printf " colorly [MESSAGE] [options]\n"
34+
printf " colorly --help | -h\n"
35+
printf " colorly --version\n"
3636
echo
3737

3838
if [[ -n $long_usage ]]; then
39-
echo -e "Options:"
39+
printf "Options:\n"
4040
# :command.usage_fixed_flags
4141
echo " --help, -h"
42-
echo -e " Show this help"
42+
printf " Show this help\n"
4343
echo
4444
echo " --version"
45-
echo -e " Show version number"
45+
printf " Show version number\n"
4646
echo
4747

4848
# :command.usage_args
49-
echo -e "Arguments:"
49+
printf "Arguments:\n"
5050

5151
# :argument.usage
5252
echo " MESSAGE"
53-
echo -e " Message to show [default: hello colors]"
53+
printf " Message to show [default: hello colors]\n"
5454
echo
5555

5656
fi
@@ -71,31 +71,31 @@ inspect_args() {
7171
# Usage:
7272
# Use any of the functions below to color or format a portion of a string.
7373
#
74-
# echo "before $(red this is red) after"
75-
# echo "before $(green_bold this is green_bold) after"
74+
# echo "before $(red this is red) after"
75+
# echo "before $(green_bold this is green_bold) after"
7676
#
7777
# ---
7878

79-
red() { echo -e "\e[31m$*\e[0m" ; }
80-
green() { echo -e "\e[32m$*\e[0m" ; }
81-
yellow() { echo -e "\e[33m$*\e[0m" ; }
82-
blue() { echo -e "\e[34m$*\e[0m" ; }
83-
magenta() { echo -e "\e[35m$*\e[0m" ; }
84-
cyan() { echo -e "\e[36m$*\e[0m" ; }
85-
bold() { echo -e "\e[1m$*\e[0m" ; }
86-
underlined() { echo -e "\e[4m$*\e[0m" ; }
87-
red_bold() { echo -e "\e[1;31m$*\e[0m" ; }
88-
green_bold() { echo -e "\e[1;32m$*\e[0m" ; }
89-
yellow_bold() { echo -e "\e[1;33m$*\e[0m" ; }
90-
blue_bold() { echo -e "\e[1;34m$*\e[0m" ; }
91-
magenta_bold() { echo -e "\e[1;35m$*\e[0m" ; }
92-
cyan_bold() { echo -e "\e[1;36m$*\e[0m" ; }
93-
red_underlined() { echo -e "\e[4;31m$*\e[0m" ; }
94-
green_underlined() { echo -e "\e[4;32m$*\e[0m" ; }
95-
yellow_underlined() { echo -e "\e[4;33m$*\e[0m" ; }
96-
blue_underlined() { echo -e "\e[4;34m$*\e[0m" ; }
97-
magenta_underlined() { echo -e "\e[4;35m$*\e[0m" ; }
98-
cyan_underlined() { echo -e "\e[4;36m$*\e[0m" ; }
79+
red() { printf "\e[31m%b\e[0m\n" "$*"; }
80+
green() { printf "\e[32m%b\e[0m\n" "$*"; }
81+
yellow() { printf "\e[33m%b\e[0m\n" "$*"; }
82+
blue() { printf "\e[34m%b\e[0m\n" "$*"; }
83+
magenta() { printf "\e[35m%b\e[0m\n" "$*"; }
84+
cyan() { printf "\e[36m%b\e[0m\n" "$*"; }
85+
bold() { printf "\e[1m%b\e[0m\n" "$*"; }
86+
underlined() { printf "\e[4m%b\e[0m\n" "$*"; }
87+
red_bold() { printf "\e[1;31m%b\e[0m\n" "$*"; }
88+
green_bold() { printf "\e[1;32m%b\e[0m\n" "$*"; }
89+
yellow_bold() { printf "\e[1;33m%b\e[0m\n" "$*"; }
90+
blue_bold() { printf "\e[1;34m%b\e[0m\n" "$*"; }
91+
magenta_bold() { printf "\e[1;35m%b\e[0m\n" "$*"; }
92+
cyan_bold() { printf "\e[1;36m%b\e[0m\n" "$*"; }
93+
red_underlined() { printf "\e[4;31m%b\e[0m\n" "$*"; }
94+
green_underlined() { printf "\e[4;32m%b\e[0m\n" "$*"; }
95+
yellow_underlined() { printf "\e[4;33m%b\e[0m\n" "$*"; }
96+
blue_underlined() { printf "\e[4;34m%b\e[0m\n" "$*"; }
97+
magenta_underlined() { printf "\e[4;35m%b\e[0m\n" "$*"; }
98+
cyan_underlined() { printf "\e[4;36m%b\e[0m\n" "$*"; }
9999

100100
# :command.command_functions
101101

@@ -127,7 +127,7 @@ parse_requirements() {
127127
case "$key" in
128128

129129
-* )
130-
echo -e "invalid option: $key"
130+
printf "invalid option: %s\n" "$key"
131131
exit 1
132132
;;
133133

@@ -137,7 +137,7 @@ parse_requirements() {
137137
args[message]=$1
138138
shift
139139
else
140-
echo -e "invalid argument: $key"
140+
printf "invalid argument: %s\n" "$key"
141141
exit 1
142142
fi
143143
;;

examples/colors/src/lib/colors.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@
55
# Usage:
66
# Use any of the functions below to color or format a portion of a string.
77
#
8-
# echo "before $(red this is red) after"
9-
# echo "before $(green_bold this is green_bold) after"
8+
# echo "before $(red this is red) after"
9+
# echo "before $(green_bold this is green_bold) after"
1010
#
1111
# ---
1212

13-
red() { echo -e "\e[31m$*\e[0m" ; }
14-
green() { echo -e "\e[32m$*\e[0m" ; }
15-
yellow() { echo -e "\e[33m$*\e[0m" ; }
16-
blue() { echo -e "\e[34m$*\e[0m" ; }
17-
magenta() { echo -e "\e[35m$*\e[0m" ; }
18-
cyan() { echo -e "\e[36m$*\e[0m" ; }
19-
bold() { echo -e "\e[1m$*\e[0m" ; }
20-
underlined() { echo -e "\e[4m$*\e[0m" ; }
21-
red_bold() { echo -e "\e[1;31m$*\e[0m" ; }
22-
green_bold() { echo -e "\e[1;32m$*\e[0m" ; }
23-
yellow_bold() { echo -e "\e[1;33m$*\e[0m" ; }
24-
blue_bold() { echo -e "\e[1;34m$*\e[0m" ; }
25-
magenta_bold() { echo -e "\e[1;35m$*\e[0m" ; }
26-
cyan_bold() { echo -e "\e[1;36m$*\e[0m" ; }
27-
red_underlined() { echo -e "\e[4;31m$*\e[0m" ; }
28-
green_underlined() { echo -e "\e[4;32m$*\e[0m" ; }
29-
yellow_underlined() { echo -e "\e[4;33m$*\e[0m" ; }
30-
blue_underlined() { echo -e "\e[4;34m$*\e[0m" ; }
31-
magenta_underlined() { echo -e "\e[4;35m$*\e[0m" ; }
32-
cyan_underlined() { echo -e "\e[4;36m$*\e[0m" ; }
13+
red() { printf "\e[31m%b\e[0m\n" "$*"; }
14+
green() { printf "\e[32m%b\e[0m\n" "$*"; }
15+
yellow() { printf "\e[33m%b\e[0m\n" "$*"; }
16+
blue() { printf "\e[34m%b\e[0m\n" "$*"; }
17+
magenta() { printf "\e[35m%b\e[0m\n" "$*"; }
18+
cyan() { printf "\e[36m%b\e[0m\n" "$*"; }
19+
bold() { printf "\e[1m%b\e[0m\n" "$*"; }
20+
underlined() { printf "\e[4m%b\e[0m\n" "$*"; }
21+
red_bold() { printf "\e[1;31m%b\e[0m\n" "$*"; }
22+
green_bold() { printf "\e[1;32m%b\e[0m\n" "$*"; }
23+
yellow_bold() { printf "\e[1;33m%b\e[0m\n" "$*"; }
24+
blue_bold() { printf "\e[1;34m%b\e[0m\n" "$*"; }
25+
magenta_bold() { printf "\e[1;35m%b\e[0m\n" "$*"; }
26+
cyan_bold() { printf "\e[1;36m%b\e[0m\n" "$*"; }
27+
red_underlined() { printf "\e[4;31m%b\e[0m\n" "$*"; }
28+
green_underlined() { printf "\e[4;32m%b\e[0m\n" "$*"; }
29+
yellow_underlined() { printf "\e[4;33m%b\e[0m\n" "$*"; }
30+
blue_underlined() { printf "\e[4;34m%b\e[0m\n" "$*"; }
31+
magenta_underlined() { printf "\e[4;35m%b\e[0m\n" "$*"; }
32+
cyan_underlined() { printf "\e[4;36m%b\e[0m\n" "$*"; }

0 commit comments

Comments
 (0)