1

I'm trying to write a script that accepts a parameter ($1) with backslashes and I want my script to echo the parameter ($1) exactly with the backslashes entered back.

e.g.

$ ./tst \\abc\def\ghi\jkl\lmn\ \\abc\def\ghi\jkl\lmn\ 

My tst script at present looks like this;

#!/bin/bash echo $1 

When I run my script it returns;

\abcdefghijkllmn 

I want it to return:

\\abc\def\ghi\jkl\lmn\ 

Exactly what I entered. I've even tried echo -E $1 but that made no difference.

Any suggestions I could achieve my desirable returned output from my script would be very much appreciated.

0

1 Answer 1

5

Try passing the parameter(s) to your script using single quotes ('). Without that, your shell is eating them before your script even sees the parameter.

$ ./tst '\\abc\def\ghi\jkl\lmn\' 
1
  • 1
    You script should also use echo "$1"; unquoted, the shell will process $1 before passing the result to echo. Commented Sep 21, 2017 at 12:01

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.