Skip to main content
added 76 characters in body
Source Link
Stéphane Chazelas
  • 587k
  • 96
  • 1.1k
  • 1.7k

When you run

test="-efoo"; echo ${test:0:2}

echo is run with the argument -e, which in some echo implementations including the echo builtin command of most bash deployments, is a valid option and is thus “swallowed”.

Use printf instead:

test="-efoo"; printf %s\\n $"${test:0:2}"

When you run

test="-efoo"; echo ${test:0:2}

echo is run with the argument -e, which is a valid option and is thus “swallowed”.

Use printf instead:

test="-efoo"; printf %s\\n ${test:0:2}

When you run

test="-efoo"; echo ${test:0:2}

echo is run with the argument -e, which in some echo implementations including the echo builtin command of most bash deployments, is a valid option and is thus “swallowed”.

Use printf instead:

test="-efoo"; printf %s\\n "${test:0:2}"
Link to the canonical answer (thanks Jeff).
Source Link
Stephen Kitt
  • 483.6k
  • 60
  • 1.2k
  • 1.4k

When you run

test="-efoo"; echo ${test:0:2}

echo is run with the argument -e, which is a valid option and is thus “swallowed”.

Use printf insteadUse printf instead:

test="-efoo"; printf %s\\n ${test:0:2}

When you run

test="-efoo"; echo ${test:0:2}

echo is run with the argument -e, which is a valid option and is thus “swallowed”.

Use printf instead:

test="-efoo"; printf %s\\n ${test:0:2}

When you run

test="-efoo"; echo ${test:0:2}

echo is run with the argument -e, which is a valid option and is thus “swallowed”.

Use printf instead:

test="-efoo"; printf %s\\n ${test:0:2}
Source Link
Stephen Kitt
  • 483.6k
  • 60
  • 1.2k
  • 1.4k

When you run

test="-efoo"; echo ${test:0:2}

echo is run with the argument -e, which is a valid option and is thus “swallowed”.

Use printf instead:

test="-efoo"; printf %s\\n ${test:0:2}