10-01-2003
Reza.
How much do you know about shell scripting? Those are basic questions. You may do well to do some reading on Bourne, Korn and C shells in Unix. A simple search on the Internet should turn up some useful pages. Use keywords like "Bourne" "Korn" "C Shell" "Unix" "Scripting" or "Tutorial".
1. In Bourne and Korn shell you can define a variable at any time by assigning a value to it:
MYVAR=some_value
Note there are no spaces around the '=' sign and the variable name is upper case by convention.
You may return the value of a variable by preceding the name with a dollar sign:
echo $MYVAR
A script may also receive parameters from the command line in variables $1, $2 ... $9.
e.g
echo $5
would return the 5th command line argument.
So:
MY_FILE=/tmp/output.txt
cat /dev/null > $MY_FILE
or ...
cp $3 $MYFILE.old
Ok. Theres a start with shell script variables. Find out what more you can do with them.
2. To obtain a value from the user use the 'read' command. This command is built into the shell and should always be availalbe to you:
read MY_FILE
The user must enter their value followed by a carriage return, before the value is committed to the variable.
You may then access the value in the variable as before:
echo $MY_FILE
I have given you a very brief and limited overview of Bourne/Korn shell variables, but I really do recommend that you do some futher reading on this topic.
Hope this helps.
MBB
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hey,
I have finally made a command that works and now has to run it on 200+ files to run it on.
How do I do that?
Just fyi and if it complicates anything my commandline is:
awk '{if ($1 ~ /1/) print $2}' file
(yup, is should print $2 if $1 is a certain value)
It doesn't work when I: ... (2 Replies)
Discussion started by: lost
2 Replies
2. Shell Programming and Scripting
hi Friends,
Please help me in writing shell script to run list of sql files.
database is Oracle 9i,
unix os is solaris
Requirement is
1. sql file must take two inputs a)feed id and b)business date
2.shell script must out put .xls or .csvfile as out put without trimming any column name and... (1 Reply)
Discussion started by: balireddy_77
1 Replies
3. Shell Programming and Scripting
Hi,
Is there any cleaver way to run function from the bash scrip over ssh?
For example:
#!/bin/bash
#Function 1
FN1 ()
{
ls -l
}
#Main run
ssh user@host FN1
exit 0
Yeah, I know it will not work, but I'm asking how to make it to work :)
I'm suspecting that it would be... (1 Reply)
Discussion started by: columb
1 Replies
4. Shell Programming and Scripting
Hi
I have the following script :
#!/bin/ksh
#################### Function macAddressFinder ########################
macAddressFinder()
{
`ifconfig -a > ipInterfaces`
`cat ipInterfaces`
}
#######################################################################
#
#
print... (2 Replies)
Discussion started by: presul
2 Replies
5. Shell Programming and Scripting
I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies
6. Shell Programming and Scripting
hello,
I need help in Unix scripting
I have a whole list of file name in a Input file. I need to run the command iteratively and output the result into a text file
e.g
While read < Input file ; do
QUERY filenane
done > output.txt
Appreciate your help
Thank you
Suhas;) (8 Replies)
Discussion started by: Suhas Kurse
8 Replies
7. Shell Programming and Scripting
HI,
I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this:
1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies
8. Shell Programming and Scripting
I have a script that I need to run on one file at a time. Unfortunately using for i in F* or cat F* is not possible. When I run the script using that, it jumbles the files and they are out of order. Here is the script:
gawk '{count++; keyword = $1}
END {
for (k in count)
{if (count == 2)... (18 Replies)
Discussion started by: newbie2010
18 Replies
9. UNIX for Dummies Questions & Answers
Hi Guys,
I've been having a look around to try and understand how i can do the below however havent come across anything that will work.
Basically I have a parser script that I need to run across all files in a certain directory, I can do this one my by one on comand line however I... (1 Reply)
Discussion started by: mutley2202
1 Replies
10. Shell Programming and Scripting
Dear All.
I have a script, which process files one by one. In the script I have two functions.
one sftp files to different server
the other from existing file create file with different name.
My question is:
Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies