Shell Scripting: using grep and tr in shebang

I have this script on my system:

#! /bin/grep cat

caterpillar
cat
lol
morecat

When I run it, I get the output as expected

#! /bin/grep cat
caterpillar
cat
morecat

But, if I use tr instead, with a script

#! /usr/bin/tr 'a' 'e'

caterpillar
cat
lol
morecat

I expect to receive

#! /usr/bin/tr 'a' 'e'

ceterpiller
cet
lol
morecet

But instead, nothing is printed, and if I manually type cat, I get c/t. How can I modify a script to behave like the first?

+4
source share
1 answer

The shebang string supports only one argument. Spaces are included literally and there are no quotes. So the command you run is equivalent to this from the shell:

tr "'a' 'e'"

, , tr . script ? , . shebang cat grep , cat grep , shebang script . ( #!/bin/sh script, /bin/sh scriptname)

,

tr "'a' 'e'" yourscriptname

tr 2 , , stdin, , , .

shebang ,

#!/usr/bin/tr 'a' 'e' <

. shebang - , .

+8

Source: https://habr.com/ru/post/1531961/


All Articles