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.

Community
  • 1
  • 1
jublikon
  • 3,427
  • 10
  • 44
  • 82
  • sh is not same as bash – Sundeep Apr 27 '17 at 08: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. – grail Apr 27 '17 at 08:47

1 Answers1

2

First line is not valid, change it to

#!/bin/bash

And it should work.

Zumo de Vidrio
  • 2,021
  • 2
  • 15
  • 33
  • 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 ? – jublikon Apr 27 '17 at 08:04
  • 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. – Zumo de Vidrio Apr 27 '17 at 08:05