05-11-2008
read arguments from shell
I have to write a C program using sys call (read, no fread) to read from shell all the parameters, without know how many are them.
I tryed in some ways, but I have no success.
Any Idea?
Can I use read to read from stdin?
Last edited by DNAx86; 05-11-2008 at 12:21 PM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am writing script in c shell and using this script to read the command line arguments, but it is not working. Pl. someone let me know what is the problem.
#!/bin/csh -f
if ($#argv <> 2) then
echo "you must give exactly two parameters"
else
set name1 = $argv
... (1 Reply)
Discussion started by: skumar11
1 Replies
2. Shell Programming and Scripting
In the make file
update updateq:
-------------------
----------
i want the makefile to display some messages when user gives "make update", but totally quite wehn user enters "make updateq". Can u tell me how to read these argument in makefile.
$1 doesnt work:( (3 Replies)
Discussion started by: vikashtulsiyan
3 Replies
3. Shell Programming and Scripting
Hi, Guys
I am new to shell programming and just get stuck with one simple question. please kindly help.
According to the tutorial here, we can do something like
for NODE in "ABC 10" "EFG 20"
do
set -- $NODE
echo "letter is $1, number is $2"
done
And the result will... (3 Replies)
Discussion started by: yuanli
3 Replies
4. Programming
Hello everybody,
I'm coding a program in C and i'm getting troubles with this.
I need to read a config file and store the arguments into individual variables, let's say the config file looks like the following:
#This is the configuration file...
192.168.0.1 A1:B1:C1:D1:E1:F1
192.168.0.2... (2 Replies)
Discussion started by: semash!
2 Replies
5. Shell Programming and Scripting
I have trouble getting this logic to work
#!/bin/bash
function assign_var(){
while
do
read -p "$2 :" $3
done
}
assign_var '$IPADDRESS' ipaddress IPADDRESS
Basicly, i want to make sure that entry is made (i can add more sophisticated checks later), but the idea is to recycle... (11 Replies)
Discussion started by: serverchief
11 Replies
6. Programming
I have the following piece of code. Currently the command line arguments are passed as shown below using the "= "sign. I capture the name of the argument, for example vmod and it's corresponding user parameter which is jcdint-z30.cmd.
./raytrac vmod=jcdint-z30.cmd srFile=jcdint.sr
Now I want... (12 Replies)
Discussion started by: kristinu
12 Replies
7. Shell Programming and Scripting
I am new to schell scripting . My objective is to write a ksh shell script that performs following tasks: -
1. Script reads all command line arguments (arguments are file names) and checks if it contains charachters "abc" in it.
2. If it contains "abc" it will execute a binary file xyz <command... (3 Replies)
Discussion started by: acmilan
3 Replies
8. Shell Programming and Scripting
I am developing a script where 3 other scripts are included.
This is a graph related script.
COMPLETE IDEA:
-There are 3 different graph scripts. I would like to create a master graph with all 3 in one.
-User chooses the type of graph
-User is asked to enter the required auguments (... (7 Replies)
Discussion started by: newkid.7955
7 Replies
9. Shell Programming and Scripting
Hi,
I need to get input arguments, as well as validate them. This is how I'm reading them:
#!/bin/bash
args="$@" # save arguments to variable
## Read input arguments, if so
while ; do
case $1 in
-v | --verbose ) verbose=true;;
-z | --gzip ) compression="gz";;
... (3 Replies)
Discussion started by: AlbertGM
3 Replies
10. UNIX for Advanced & Expert Users
Heays
So i have that script to which i'd like to pipe (rather than just regular arguments) some data from another virtual output command.
Simplified:
echo * | script.sh
When i know how many args i expect, i can handle this simple by:
&& \
read ONE TWO && \
set ONE TWO
echo "$1 : $2... (7 Replies)
Discussion started by: sea
7 Replies
read(1) General Commands Manual read(1)
NAME
read - Reads a line from standard input
SYNOPSIS
read [-r] var...
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
read: XCU5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
OPTIONS
Do not treat a backslash character in any special way. Consider each backslash to be part of the input line.
Note
The -r option is included to enable read to subsume the purpose of the obsolete line utility.
OPERANDS
The name of an existing or non-existing shell variable.
DESCRIPTION
The read utility reads a single line from standard input.
By default, unless the -r option is specified, backslash () acts as an escape character. If standard input is a terminal device and the
invoking shell is interactive, read prompts for a continuation line in the following cases: The shell reads an input line ending with a
backslash, unless the -r option is specified. A here-document is not terminated after a newline character is entered.
The line is split into fields as in the shell (see the sh(1) reference page); the first field is assigned to the first variable var, the
second field to the second variable var, and so forth. If there are fewer var parameters specified than there are fields, the leftover
fields and their intervening separators are assigned to the last var. If there are fewer fields than vars, the remaining vars are set to
empty strings.
The setting of variables specified by the var parameters affects the current shell execution environment. If read is called in a subshell
or separate utility execution environment, such as one of the following, it does not affect the shell variables in the caller's environ-
ment:
(read foo) nohup read ... find . -exec read ... ;
NOTES
The -r option is included to enable read to subsume the purpose of the obsolete line utility.
RESTRICTIONS
The results are undefined if an end-of-file is detected following a backslash at the end of a line when -r is not specified.
EXIT STATUS
The following exit values are returned: Successful completion. End-of-file was detected or an error occurred.
EXAMPLES
The following command prints a file with the first field of each line moved to the end of the line:
while read -r xx yy do
printf "%s %s
" "$yy" "$xx" done < input_file
ENVIRONMENT VARIABLES
The following environment variables affect the execution of read: Determines the internal field separators used to delimit fields. Pro-
vides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value
from the default locale is used. If any of the internationalization variables contain an invalid setting, the utility behaves as if none
of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization vari-
ables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed
to multibyte characters in arguments). Determines the locale used to affect the format and contents of diagnostic messages written to
standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. Provides the prompt string that an
interactive shell will write to standard error when a line ending with a backslash is read and the -r option was not specified, or if a
here-document is not terminated after a newline character is entered.
SEE ALSO
Commands: line(1)
Functions: fread(3)
Standards: standards(5)
read(1)