[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash, dash and sh



On 04/22/2015 08:02 PM, jeremy bentham wrote:
I have a bunch of scripts ...
with the first line #!/bin/sh that use bashisms, ...

How about changing the shebang line of the scripts with Perl?


http://debian-administration.org/article/298/Search_and_replace_across_many_files_with_a_perl_one-liner


Note that you can leave off the -i switch to Perl while developing your code snippet and/or regular expression, and Perl will print the munged results to STDOUT rather than clobbering your file(s):

2015-04-22 20:30:58 dpchrist@t2250 ~/sandbox/sh
$ ll hello.sh
-rwxr-xr-x 1 dpchrist dpchrist 31 2015/04/22 20:30:51 hello.sh*

2015-04-22 20:31:02 dpchrist@t2250 ~/sandbox/sh
$ cat hello.sh
#!/bin/sh
echo "hello, world!"

2015-04-22 20:31:04 dpchrist@t2250 ~/sandbox/sh
$ ./hello.sh
hello, world!

2015-04-22 20:31:08 dpchrist@t2250 ~/sandbox/sh
$ perl -p -e 's(#!/bin/sh)(#!/bin/bash)' hello.sh
#!/bin/bash
echo "hello, world!"

2015-04-22 20:31:14 dpchrist@t2250 ~/sandbox/sh
$ cat hello.sh
#!/bin/sh
echo "hello, world!"

2015-04-22 20:31:19 dpchrist@t2250 ~/sandbox/sh
$ perl -pi -e 's(#!/bin/sh)(#!/bin/bash)' hello.sh

2015-04-22 20:31:26 dpchrist@t2250 ~/sandbox/sh
$ cat hello.sh
#!/bin/bash
echo "hello, world!"

2015-04-22 20:31:29 dpchrist@t2250 ~/sandbox/sh
$ ./hello.sh
hello, world!


David


Reply to: