0

Hi,
How will i grep for a string which has '/' in it.

I have so many script files some are having

#!/bin/bash

and some are having

#!/bin/sh

how can i find the scripts which are having #!/bin/sh.

Thanks

3
Contributors
2
Replies
19
Views
3 Years
Discussion Span
Last Post by rch1231
0

Just put single quotes around the searched-for string:

grep '#!/bin/bash' filename

or use back-slashes to escape all the special characters

grep \#\!\/bin\/bash filename

0

Hello,

The easiest method is to enclose what you are looking for in quotes and the only charactor you have to escape is the backslash (because of the history command). For example you could run the following which would find all of the files in the /bin directory that use #!/bin/bash:

[root@lptp2 ~]# grep "#\!/bin/bash" /bin/*
/bin/abrt-action-save-kernel-data:#!/bin/bash
/bin/alsa-info:#!/bin/bash
/bin/alsa-info.sh:#!/bin/bash
/bin/animal-sniffer:#!/bin/bash
/bin/auto-br:#!/bin/bash -
/bin/auto-br-rpmbuild:#!/bin/bash -
/bin/blueproximity:#!/bin/bash
.
.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.