1828676 Members
2294 Online
109984 Solutions
New Discussion

Shell script help needed

 
Debbie Fleith
Regular Advisor

Shell script help needed

I pulled a shell script from HP-UX and it doesn't display right under Linux.

What is the equivalent "new line" and "tab" entries for Linux since the backslash entries show explicitly under Linux?

In this sample below, all of my \n and \t's show up.
=========================
echo "\n\n"
echo "\t\tSelect the database that you would like to use:"
echo "\n"
echo "\t\t\t[1] Colorado Springs\n"
echo "\t\t\t[2] Tucson"
=========================
5 REPLIES 5
Jordan Bean
Honored Contributor

Re: Shell script help needed

The echo command is different in bash. Use the -e option to enable special characters.

echo -e "\n\n"

Che Cordes
Valued Contributor

Re: Shell script help needed

Or use the printf command (formatted print). I believe it is perfered under linux. Your script above will work fine by changing all instances of echo to printf. With printf, however, a carriage return is not implied and therefore you would want to append another newline call after Tuscon or the command prompt will appear on this line.

Che'
Dave Pointon
New Member

Re: Shell script help needed

IMHO, the most elegant solution is to use a here document in the script - where all characters between the '!' marks are cat(1)ed to stdout ad verbatim - as follows:

cat << !


Select the database that you would like to use:

[1] Colorado Springs
[2] Tucson
=========================
!

HTH,

DP
James Brandvold
New Member

Re: Shell script help needed

The simplest solution is to add:

#!/bin/csh

as the first line of the script. The 'c' shell interprets these characters correctly and you won't have to search for every instance of the echo command.
Heiner E. Lennackers
Respected Contributor

Re: Shell script help needed

I doubt that this is the simplest soultion or a solution at all. If you do not know the whole script you cannot know, if it would run in a csh (most OS scripts are written in bourne-sh to be compatible with almost everything).

You can try to alias the echo command like:
alias echo="echo -e "
this runs fine in a linux bash.

This is my favorite solution to test foreign scripts.

Heiner
if this makes any sense to you, you have a BIG problem