Tag: bash

Env for scripts interpreter searching

Posted by – February 15, 2012

#!/usr/bin/env bash
Probably the most common use of env is to find the correct interpreter
for a script, when the interpreter may be in different directories on
different systems.  The following example will find the `perl’ inter-
preter by searching through the directories specified by PATH.
1.  #!/usr/bin/env perl
One limitation of that example is that it assumes the user’s value for
PATH is set to a value which will find the interpreter you want to exe-
cute.  The -P option can be used to make sure a specific list of directo-
ries is used in the search for utility.  Note that the -S option is also
required for this example to work correctly.
2. #!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds `perl’ only if it is in /usr/local/bin or /usr/bin.  That
could be combined with the present value of PATH, to provide more flexi-
bility.  Note that spaces are not required between the -S and -P options:
3. #!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl

#!/usr/bin/env bash
Probably the most common use of env is to find the correct interpreter     for a script, when the interpreter may be in different directories on     different systems.  The following example will find the `perl’ inter-     preter by searching through the directories specified by PATH.
1.  #!/usr/bin/env perl     One limitation of that example is that it assumes the user’s value for     PATH is set to a value which will find the interpreter you want to exe-     cute.  The -P option can be used to make sure a specific list of directo-     ries is used in the search for utility.  Note that the -S option is also     required for this example to work correctly.
2. #!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds `perl’ only if it is in /usr/local/bin or /usr/bin.  That     could be combined with the present value of PATH, to provide more flexi-     bility.  Note that spaces are not required between the -S and -P options:
3. #!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl

Env

Posted by – February 15, 2012

#!/usr/bin/env bash
Probably the most common use of env is to find the correct interpreter
for a script, when the interpreter may be in different directories on
different systems.  The following example will find the `perl’ inter-
preter by searching through the directories specified by PATH.
1.  #!/usr/bin/env perl
One limitation of that example is that it assumes the user’s value for
PATH is set to a value which will find the interpreter you want to exe-
cute.  The -P option can be used to make sure a specific list of directo-
ries is used in the search for utility.  Note that the -S option is also
required for this example to work correctly.
2. #!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds `perl’ only if it is in /usr/local/bin or /usr/bin.  That
could be combined with the present value of PATH, to provide more flexi-
bility.  Note that spaces are not required between the -S and -P options:
3. #!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl

#!/usr/bin/env bash
Probably the most common use of env is to find the correct interpreter     for a script, when the interpreter may be in different directories on     different systems.  The following example will find the `perl’ inter-     preter by searching through the directories specified by PATH.
1.  #!/usr/bin/env perl     One limitation of that example is that it assumes the user’s value for     PATH is set to a value which will find the interpreter you want to exe-     cute.  The -P option can be used to make sure a specific list of directo-     ries is used in the search for utility.  Note that the -S option is also     required for this example to work correctly.
2. #!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds `perl’ only if it is in /usr/local/bin or /usr/bin.  That     could be combined with the present value of PATH, to provide more flexi-     bility.  Note that spaces are not required between the -S and -P options:
3. #!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl

Bash Colors

Posted by – June 20, 2011

Bash Color Escape Codes

Echo (echo -e) the following escape codes inside \e[ESCCODEm to colorize text in Bash:

  • Black 0;30
  • Dark Gray 1;30
  • Blue 0;34
  • Light Blue 1;34
  • Green 0;32
  • Light Green 1;32
  • Cyan 0;36
  • Light Cyan 1;36
  • Red 0;31
  • Light Red 1;31
  • Purple 0;35
  • Light Purple 1;35
  • Brown 0;33
  • Yellow 1;33
  • Light Gray 0;37
  • White 1;37

Make sure to use echo -e to enable interpretation of backslash escapes:

bash$ echo -e "This is red->\e[00;31mRED\e[00m"

Remove Color

Echo \e[00m to remove text color modifications:

bash$ echo -n '\e[00m'