1834137 Members
2386 Online
110064 Solutions
New Discussion

Shell Script

 
Syed F Hashim
New Member

Shell Script

Hi Gurus,

I need to write a shell script, (in vi), I have to put line feed or carage return character within the script.
Basically the purpose is not to have interaction with the user (replies), whereas go on the default behaviour.
I just need to put "ENTER" 7 times in my script, which character should I use, either I have to write, decimal, octal or hexadeciaml.
Can't work, you people help will highly be appreciated.
Thanks in advance.
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: Shell Script

It depends upon which character you program is actually expecting.

Note the the echo command normally terminates with a LF unless you specifically override this behavior by ending the echo command with "\c"

To emit a single CR use "\r" followed by "\c"
e.g.

echo "\r\c"

because normally CR's are converted to NL's (you can determine this by doing a stty -a to see if icrnl is set) you can choose to either send a string of CR's or simply (and more conveniently use echo's without \c to emit the NL's for you.

About as simple as it gets is
echo "\n\n\n\n\n\n"

That will emit 7 NL's (the 6 explicit + the 1 implicit because we did not end the command with "\c".

If it ain't broke, I can fix that.
John Kittel
Trusted Contributor

Re: Shell Script

Carriage return character is 0D ( in hexadecimal). Linefeed is 0A. These display as ^M ( carriage return ) and ^J ( linefeed).

With vi, to enter a literal carriage return or linefeed into a text file, use the key sequence: control-V control-M
for carriage return.

use control-V control-J
for linefeed.
Bharat Katkar
Honored Contributor

Re: Shell Script

Hi,
Just add:
read
in your script as many times you want your script to wait for Key.
This will wait till the user hit's Enter key.

If you want to add Carraige Return without anybodies intervention then just add:
echo "\n"
as many time you want in your script.

That should work.
Regards,
You need to know a lot to actually know how little you know
KapilRaj
Honored Contributor

Re: Shell Script

echo "\n" should work

Also

echo "CTRL+V+M" >>filename #Kornshell am not sure if it works in posix

Kaps
Nothing is impossible
Syed F Hashim
New Member

Re: Shell Script

Thanks a lot Gurus:

The solutions echo "\n\n\n" works.

Thanks again for your help.
Bharat Katkar
Honored Contributor

Re: Shell Script

Hi Syed,
Nice to see that your problem got solved. I think you are new to forum, go thr' the link below about assigning points to the replies you got.

http://forums1.itrc.hp.com/service/forums/helptips.do?admit=716493758+1085211538437+28353475#33

All the best.
Keep forumming.
Regards,
You need to know a lot to actually know how little you know