Skip to main content
edited body
Source Link
Stéphane Chazelas
  • 586.4k
  • 96
  • 1.1k
  • 1.7k

zsh echo behaves the standard way, like bash in UnixUNIX mode. That is it expands \b to the ASCII BS character as the UnixUNIX specification requires.

Don't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell but rc), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

zsh echo behaves the standard way, like bash in Unix mode. That is it expands \b to the ASCII BS character as the Unix specification requires.

Don't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell but rc), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

zsh echo behaves the standard way, like bash in UNIX mode. That is it expands \b to the ASCII BS character as the UNIX specification requires.

Don't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell but rc), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

zsh echo behaves the standard way, like bash in Unix mode. That is it expands \b to the ASCII BS character as the Unix specification requires.

Don't use echo to display arbitrary strings, use printfDon't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell but rc), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

zsh echo behaves the standard way, like bash in Unix mode. That is it expands \b to the ASCII BS character as the Unix specification requires.

Don't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell but rc), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

zsh echo behaves the standard way, like bash in Unix mode. That is it expands \b to the ASCII BS character as the Unix specification requires.

Don't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell but rc), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

added 9 characters in body
Source Link
Stéphane Chazelas
  • 586.4k
  • 96
  • 1.1k
  • 1.7k

zsh echo behaves the standard way, like bash in Unix mode. That is it expands \b to the ASCII BS character as the Unix specification requires.

Don't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell but rc), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

zsh echo behaves the standard way, like bash in Unix mode. That is it expands \b to the ASCII BS character as the Unix specification requires.

Don't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

zsh echo behaves the standard way, like bash in Unix mode. That is it expands \b to the ASCII BS character as the Unix specification requires.

Don't use echo to display arbitrary strings, use printf:

printf '%s\n' "$1" 

print -r -- "$1" also works but is ksh/zsh specific.

echo -E - "$1" work with zsh and I believe some BSDs.

cat << EOF $1 EOF 

works in any Bourne-like shell even those from a few decades when there was no printf command but it spawn a new process, and is really not necessary nowadays as we now have printf everywhere.

And by the way, you need to escape backslashes on a shell command line as it's special to the shell (every shell but rc), so:

$ foo '\\foo\bar' 

foo \\foo\bar would pass the "\foo\bar" string to foo which can't reinvent the lost backslash back.

added 109 characters in body
Source Link
Stéphane Chazelas
  • 586.4k
  • 96
  • 1.1k
  • 1.7k
Loading
Source Link
Stéphane Chazelas
  • 586.4k
  • 96
  • 1.1k
  • 1.7k
Loading