/bin/sh Execution problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting /bin/sh Execution problem
# 1  
Old 01-29-2014
/bin/sh Execution problem

I am trying to explore HERE Document in UNIX.
Here is the sample script that i am trying to execute:
Code:
#!/bin/sh
filename=sample.txt
vi $filename <<EOF
i

This file was created automatically from
a shell script.
Code:
^[
:wq
EOF

Here is the error i received when i execute above script:
Code:
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.

Can someone please help me out? I guess Vim is not reading "^[" as escape key<esc>. are there any environment variable setup to be changed so that Vim can interpret "^[" as escape?

Thank You!

Last edited by Scott; 01-30-2014 at 12:31 AM.. Reason: Use code tags, please...
# 2  
Old 01-29-2014
There are much better ways to change files from command line/script (eg awk,sed).

But if you insist on using vim, you can try using a vim script file (with the -s option)

Code:
#!/bin/sh
filename=sample.txt
dummy=/tmp/$$vim.script

cat > $dummy <<EOF
iThis file was created automatically from
a shell script.^[:wq
EOF

vim -s $dummy $filename

rm $dummy

Make sure you use <ctrl-V>ESC to insert ^[ into your script when writing in vim.
# 3  
Old 01-29-2014
vi is a visual editor. look at ex (part of vi), or ed. they don't require a terminal.
# 4  
Old 01-30-2014
Thank You

Chubler_XL and neutronscott: thanks for your input.

Chubler_XL: I tried your code it worked. and my code too worked after i did <Ctrl+V> for ESC. Before i was entering character"^[". Hence it wasn't working.
Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

2. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

3. Solaris

Execution problem with "/usr/dt/bin/sdtdbcache

On a SunOS Solaris 5.5.1 workstation, the /usr/dt/bin/sdtdbcache –init command lasts more than 20 minutes. This command is executed by the /usr/dt/bin/Xsession script during an user connection. Please refrain from using subjects like "HELP ME!..." to get more/faster attention and also please do... (1 Reply)
Discussion started by: ricadom
1 Replies

4. Shell Programming and Scripting

Problem in /bin/bash with stty erase

hello everybody, as many, I have a problem with a script... I wrote a shell script in which I want to read a variable value. the problem is that I can't use the arrow keys. Here is the script I use : #!/bin/bash stty erase ^H read foune echo "$foune" exit 0; the problem is... (2 Replies)
Discussion started by: Moumou
2 Replies

5. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

6. Shell Programming and Scripting

/bin/sh and /bin/ksh problem

we have a shell script that we are using in KSH if ]; then _IFS=$IFS IFS=: and it's failing on /bin/sh . Is there a simple way to modify it to work on both . ( not with awk) Thanks in adv (3 Replies)
Discussion started by: talashil
3 Replies

7. Shell Programming and Scripting

Problem with /usr/bin/cd command

Hi , My shell script doesnt function properly while executing. My shell script has the below mentioned code in it. #!/bin/sh CD="/usr/bin/cd" .. .. $CD / .. .. main intention behind giving the $CD / is to replace the cd command with /usr/bin/cd at the time of program execution. ... (5 Replies)
Discussion started by: raghu.amilineni
5 Replies

8. UNIX for Dummies Questions & Answers

problem in /var/log/messages and /usr/bin/last

Unfortunately., i had remove the files /var/log/messages and /usr/bin/last in our server, we have to touch another one and change the permissions also but not working still now. help me yours thakshina (2 Replies)
Discussion started by: thakshina
2 Replies

9. Linux

Problem with /usr/bin

I installed an application in this location /root/jython and I added a link to the /usr/bin because i want everyone on the system to be able to execute this ln -s /root/jython/jython jython I can execute this anywhere when i am logged in as root but when i change user to say juju it returns ... (1 Reply)
Discussion started by: oyesiji
1 Replies

10. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question