I am new to linux and its shell programming.
I wrote a shell script on ubuntu and linux mint which is working perfectly on their systems.
Now when I tried to run this shell script on red hat , whole output is weird.
Problem:
\n characters are printed as it is , no new line is being printed.
some errors occuring like
expr:non-integer argument
.I have used only three types of statements for comparison -1. if [ "$proto" = "TCP" ] 2. if [ "$prot_no" = "06" ] 3. if [ "$i" -eq 32 ]
I don't know where exactly is the error but there was no error on ubuntu and mint systems.
I have heard that Default shell in ubuntu is bash
while in red hat is ksh
but I am not sure about this.
If this is the case then how can I change my shell or if possible is there any command by which I can run my script through bash shell so that there would not be any need to make any change in the script.
Please help me .... It is almost impossible to change all \n
characters in the script.
Edit:
for
\n
issue this is a sample line ..echo "\n\n$proto Header"
for other errors here is some code which may possibly help ...
if [ "$trans_or_tunn" -eq 1 ] then prot_no=`head -n 1 decrypt.txt | awk -F " " '{printf "%s",$7}'` if [ "$prot_no" = "06" ] then proto="TCP" else if [ "$prot_no" = "11" ] then proto="UDP" else if [ "$prot_no" = "3a" ] then proto="ICMP" fi fi .....
echo "\n\n$proto Header"
this line was supposed to print one of the three values ..TCP HEADER
,UDP HEADER
orICMP HEADER
.
but what is actually printed out on screen is ..
Output on screen for above line
\n\nHeader
\n
issue we'll need to see sample code where you attempt to print the newline. The non-integer argument is due to a variable expanding to a non-integer value or being empty; if you know which line this error occurs on that would help. The default shell doesn't matter as long as your script's bang line is correct. If you need bash specify bash. – sorpigal$trans_or_tunn
does not contain an integer. I imagine it contains the stringexpr
. Where's the code that assigns to it? Have you tried turning onset -x
? – sorpigal