script/program in vi include $? or...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers script/program in vi include $? or...
# 1  
Old 03-18-2009
script/program in vi include $? or...

Hi. When you write a script/program in vi Do you include the $ Eg. #!/bin/bash $ echo "Today's date is `date`" or echo "Today's date is `date`" Make your script executable. $chmod +x script I included that. I keep getting a permission denied... why? Thanks!
# 2  
Old 03-18-2009
Hi. When you write a script/program in vi . Do you include the $ Eg. . $ echo "Today's date is `date`" or . echo "Today's date is `date`" . Make your script executable. . $chmod +x script I included that. . I keep getting a permission denied... why? Thanks!
# 3  
Old 03-18-2009
You will need to explain your problem a little better.

1) You are creating a script in vi. I do not understand what you mean by "do you include...".

Scripts are flat ASCII files with shell or program specific commands. Please clarify your question.

2) I assume you mean in the execution of the saved scriptfile... if this is the case, then you will have to change the attribute of the scriptfile to allow for execution. Please see "chmod" for details. If you would like to change the file to executable:

Code:
chmod +x scriptfile

3) Your post indicated that you chmod'd the file, thus the last thing your should check is the PATH variable to make sure that the residing directory is included or execute the file with a preceding "./" ,as in ./scriptfile
# 4  
Old 03-18-2009
Sorry for double, I tried to fix the spacing.. In vi echo "Today's date is `date`" or $ echo "Today's date is `date`" Include the dollar sign or no? “Written as echo "Today's date is `date`" save and quit vi chmod 755 script -gives permission to your script ./script -executes your script” ./filenameDate echo $PATH chmod +x scriptfile or chmod +x scriptName1 I'm still confused.. 8( But I'm keep trying... Thanks
# 5  
Old 03-18-2009
Error

Step 1)

When writing scripts, you do not include the "$" at the beginning of the line, since in a shell, the "$" is actually the command prompt. The $ has a specific meaning within the shell program itself (it is used to reference variables).


Thus, in the example you supplied, vi a file called "myscript.sh". The script program would look similar to the following:

Code:
#!/bin/sh
echo "Today's date is `date`"

Note the quotes around the echo statement. This is due to the fact that you have an apostrophe within the desired phrase.

Step 2) Save the file and chmod +x myscript.sh
Step 3) ./myscript.sh

Code:
$ vi myscript.sh
$ chmod +x myscript.sh
$ ./myscript.sh



or

Step 3a) echo $PATH to see if the directory where "myscript.sh" is included, if not, include it using the following (for a Bourne/Korn shell or equivalent) into your login profile

PATH=$PATH:/newdirectorytoadd
export PATH

for csh users,

set path=($path /newdirectorytoadd)

or

setenv PATH ${PATH}:/newdirectorytoadd

(I'm not a csh power user, so double check this...)

Step 3b) at the command prompt, just execute the myscript.sh file


Code:
$ vi myscript.sh
$ chmod +x myscript.sh
$ PATH=$PATH:/this/is/the/directory
$ export PATH
$ myscript.sh


Don't think I can get much more explicit, I hope this helps.

Last edited by wabard; 03-19-2009 at 06:59 AM.. Reason: Spelling, I'm pendantic... :)
# 6  
Old 03-18-2009
Great post! I'll try it a lil later Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to include SQL within a script

Hi, I have a script I am developing (actually more than 1 just now). 1st part - executes SQL in a 2nd script. 2nd part - reformats the output of the sql into a csv Problem: How am I able to run the SQL from the first script? I assume there is a sql command? I generally use isql when... (6 Replies)
Discussion started by: mcclunyboy
6 Replies

2. UNIX for Dummies Questions & Answers

[solved] Script creation (how to include options in the script)

Hi guys i have written a script which takes the options given to him and execute itself accordingly. for example if a script name is doctortux then executing doctortux without option should made doctortux to be executed in automatic mode i.e. doctortux -a or if a doctortux is needed to run in... (4 Replies)
Discussion started by: pinga123
4 Replies

3. Shell Programming and Scripting

How to include a command in shell script?

# dbc "delete from alert;" DELETE 10 # However, the script created below generates an error that command does not exits. Can any one please exist. script.sh: #!/bin/sh dbc "delete from alert;" >>$TASKLOGFILE ./script.sh: line 38: dbc: command not found can any one please... (2 Replies)
Discussion started by: sureshcisco
2 Replies

4. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

5. Shell Programming and Scripting

include in script

Hello, I have a script and a second file that contains all parameters needed for the script. How can I include this file in the script ? I tried source but I have a "no such file or directory" error. :) (1 Reply)
Discussion started by: pppswing
1 Replies

6. UNIX for Dummies Questions & Answers

Include PERL script with in the unix shell script

Hi Gurus, Is it possible to include perl script with in the unix shell script? What would be the general syntax? In the above case, is it required to write the below first two lines of codes? #!usr/bin/sh -x #!usr/bin/perl -w Thanks in advance / Mysore Ganapati. (1 Reply)
Discussion started by: ganapati
1 Replies

7. Shell Programming and Scripting

how to include spreadsheet::ParseExcel in shell script

Please tell me that how can we include Spreadsheet::ParseExcel module in shell script (1 Reply)
Discussion started by: akash
1 Replies

8. Shell Programming and Scripting

how to include header file in b-sh script

I'm new in this. In C/C++, you define variables in one header file & then simply include it in any files where those variables are referenced. I tried to include a header named DefineVars- which initializes all the globals- but when I add the line "DefineGlobals" at the begining of another... (2 Replies)
Discussion started by: bluemoon1
2 Replies

9. Shell Programming and Scripting

Include lines within a script

I want to add lines in my script dynamically. My script: ... echo addscript end addscript ... Lines to add: (can be put in a file and can be added) cp /opt/script1.sh opt/script1_org.sh sed 's/testusr/'${FUNCTID}'/g' /opt/script1.sh > ./tmpfile mv ./tmpfile /opt/script1.sh... (1 Reply)
Discussion started by: chiru_h
1 Replies

10. Programming

How to include shell script in C program

hi I want to call a shell script in C program the script is : ssh -t user@remote sh /<remote>home/user/<file_name>.sh and other several commands C program : Call this script and the retrive the task that is been done in <file_name>.sh file can any one tell me how... (5 Replies)
Discussion started by: mridula
5 Replies
Login or Register to Ask a Question