atarallo / TECMINT_MONITOR

A Shell Script to Monitor Network, Disk Usage, Uptime, Load Average and RAM Usage in Linux. Originally published on http://www.tecmint.com
Apache License 2.0
248 stars 145 forks source link

the Shebang ? #19

Closed Sim4n6 closed 5 years ago

Sim4n6 commented 8 years ago

If you choose#!/bin/sh as shebang , it will not support TYPE cmd.

I prefer #!/bin/bash but a discussion will help figure out the right shebang

atarallo commented 8 years ago

I would like to have this script running in all UNIX availiable. We're moving in that way. Outside from Linux, you can't take bash for granted. It's very popular and user friendly, but only /bin/sh is available in all *UX.

To get the full path of a command with type (type cat outputs cat is /bin/cat) could be done with which ( which bash outputs /bin/bash).

Sim4n6 commented 8 years ago

but COLORs will not be used in /bin/sh ... ? do we have to remove the coloring ?

atarallo commented 8 years ago

Colours are given by ANSI scape sequences. Things like the TECRESET variable or "'\E[32m". It has notheing to do with the shell you choose to run your shellscripts.

Sim4n6 commented 8 years ago

Can you provide me with some documentation about that? Please

arthar360 commented 8 years ago

All systems have bash built in. Even basic ArchLinux have it. Sh is not provided "as is" nowdays. If you have a closer look, in Ubuntu, run ls -l /bin/sh . You will find it it is linked to /bin/dash . In Red Hat systems, if you run the same command, sh is linked to bash. I feel that sticking with bash as shebang will be persistent for all systems

atarallo commented 8 years ago

All Linux systems have bash as default, I'm very aware of that fact. But we are working towards a script that is not only useful in Linux.

In AIX, most installs favour ksh (korn shell) but support Bourne Shell (/bin/sh). Solaris i recall that has bourne shell as default.

This are the reasons I insist on using bourne shell instead of bash.

2016-09-16 10:09 GMT-03:00 Atharva Deshmukh notifications@github.com:

All systems have bash built in. Even basic ArchLinux have it. Sh is not provided "as is" nowdays. If you have a closer look, in Ubuntu, run ls -l /bin/sh . You will find it it is linked to /bin/dash . In Red Hat systems, if you run the same command, sh is linked to bash. I feel that sticking with bash as shebang will be persistent for all systems

atarallo commented 8 years ago

The ability to output colors is part of the terminal capabilities. If the terminal is unable to interpret ANSI scape sequences it will output garbage.

Look at this tiny script:

!/bin/sh

echo -e '\E[32m'"A Green Message"

It will run fine on Linux because of the terminal capabilities.

I've read, long time ago, about this on ncurses tutorials: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html . A good description about termcap (database&library) is on wikipedia: https://en.wikipedia.org/wiki/Termcap . Also is recomended to read about terminfo: https://en.wikipedia.org/wiki/Terminfo

Hope this answers your request.

2016-09-16 4:45 GMT-03:00 ALJI Mohamed notifications@github.com:

Can you provide me with some documentation about that? Please

Sim4n6 commented 8 years ago

the world is nice and wonderful , in theory of course.

I am using Terminator as an terminal emulator.

Well, when I switch to the shell SH (using bash -c or customizing config in Terminator )

I get strange \E[31m characters.

but It works like a charm under BASH , JUST SAYING :smile_cat:

atarallo commented 8 years ago

It's not theory. Read what I've set you and take your conclusions. ;).

Please do this: execute echo $TERM in both bash an sh. Then compare the outputs. We might take into account that many terminals doesn't support ANSI scape sequences.

Sim4n6 commented 5 years ago
echo $TERM

returns xterm-256color