1

I have created a shell script in a file named strings referring to that post:

#! /bash/sh
original_string='i love Suzi and Marry'
string_to_replace_Suzi_with='Sara'
result_string="${original_string/Suzi/$string_to_replace_Suzi_with}"

after that I have created an executable file referring to that post:

chmod +x strings

but if I run the file like that:

./strings

I get the issue:

./strings: 5: ./strings: Bad substitution

How can that be possible? I have just copied and pasted the sample code.

2
  • sh is not same as bash Commented Apr 27, 2017 at 8:00
  • Probably find that sh is not an issue, but the space between the shebang (#!) and the fact that you have not provided a path to you interpreter is a problem, so #!/bin/sh should also work. As mentioned below though, you would need to echo something to have output displayed. Commented Apr 27, 2017 at 8:47

1 Answer 1

2

First line is not valid, change it to

#!/bin/bash

And it should work.

Sign up to request clarification or add additional context in comments.

2 Comments

No I do not get no error message any more. But if I type './strings' the command line does not return anything and just jumps to a fresh prompt. Do I still miss something ?
You are not printing anything in your script. If you want to get the output of result_string, add echo "$result_string" at the end of your script.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.