Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6774879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:50:25+00:00 2026-05-26T15:50:25+00:00

I am new to linux and its shell programming. I wrote a shell script

  • 0

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:

  1. \n characters are printed as it is , no new line is being printed.

  2. 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:

  1. for \n issue this is a sample line ..

    echo "\n\n$proto Header"
    
  2. 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 or ICMP HEADER.

but what is actually printed out on screen is ..

Output on screen for above line
\n\nHeader

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:50:25+00:00Added an answer on May 26, 2026 at 3:50 pm

    Change the first line of the script from

    #!/bin/sh
    

    to

    #!/bin/bash
    

    Use echo -e to get echo to print \n as a newline.

    Use [[ ]] instead of [ ] for tests.

    Explanation: the default shell on Ubuntu is dash, not bash. This is a rather limited (but therefore fast) shell, that is unfortunately not available on all Linux platforms. bash, not ksh, was the default shell on Red Hat the last time I checked, and is available almost everywhere, so portable shell scripting requires either targeting that or writing scripts to a common subset of bash, dash and ksh. (If you’re interesting, the best portable subset is roughly that defined in the POSIX standard shell command language.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Linux and especially to Ubuntu 11 which I'm just trying today
New to Linux programming in general. I am trying to communicate with a kernel
I am trying to build a script (I'm pretty new to linux scripting) and
I'm pretty new to programming for Linux environments, so I don't exactly know what
Version info: Django version 1.3 pre-alpha SVN-13858 Ubuntu GNU/Linux 10.10 I'm totally new to
I've been working on a perl daemon for linux and here is its skeleton:
I am new to Linux shell and I found a way to get the
I am quite new to the embedded linux programming and did not really understand
I see the new Desktop class (which I'd like to use for its browse(uri)
I'm using Python 2.6 on linux. I have a run.py script which starts up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.