top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How comments are processed in shell script?

0 votes
315 views

I have noticed that in shell script comments are also useful to perform some task,
for ex:
if i write #!/bin/bash/
or if i write #!/bin/sh/

in both the example script behavior is different,
both are comments then why it is giving different behavior?

posted Aug 18, 2015 by Chirag Gangdev

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Its just a convention i.e. #! (its not #, its #!) to tell what type of the shell/interpreter it is. Your scripts can be in bash, python, perl, ruby, PHP etc by the following means

#!/bin/bash
#!/bin/sh
#!/bin/perl
#!/bin/perl5
answer Aug 18, 2015 by Salil Agrawal
Similar Questions
+2 votes

I am using below script to validate IPV6 address but this script also pass invalid IP such as empty string, name etc.

if [[ "$IPv6ADDR"=~"^:?([a-fA-F0-9]{1,4}(:|.)?){0,8}(:|::)?([a-fA-F0-9]{1,4}(:|.)?){0,8}$" ]]; then
  echo "valid ipv6 addr"
  break;
else
  echo "Invalid IP Address"
  break;
fi

Can someone identify what's wrong in the regex, Please?

0 votes

I have a shell script copyScript.sh present in my pendrive.
What i want is, Whenever i connect pendrive to my pc this script should be run automatically.

Is it possible?
If yes then how to achieve this?

...