Hi All,
Please provide me many arguments in read command .
explain clearly now .
1) i have a file 40 names in the file .
scenario with explanation :
2) read -p ( one argument is aware ) but how to pass any arguments from file .
Please guide me , how to pass argument from a file then pass name like 1 or 4 or 5 or 39 name as argument in 40 lines of the file .
How to provide required arguments in a file manually at a time execute read command in bash script .
Please provide me valuable information .
I am waiting for your valuable guidance .
Regards,
Jeesshnasree
To pass multiple items using the read command, separate the variable names with spaces:
when run:
If you are reading lines from a file, that's different. You probably need a loop to do that - one that reads a file:
In this case, the file names.txt has 40 lines in it - one name per line:
john
paul
george
...
ringo
The script reads (using read) one line at a time in a while loop. During each iteration, the line from the file is stored in the variable named linein. They are then displayed.
./test.sh
john
paul
george
...
ringo
Once read, the data from the file (the names, in this case) can be processed in some way. If all of them need to be stored as separate variables within the script, an array would be a good thing to use.
Hello @Tracy_Baker ,
Thank you .
Is it possible create a file with as per aguments & that arguments need to store as line by line in the file .
if possible as mentioned criteria then please share me script .
I am waiting for your valuable information .
Regards ,
Jeesshnasree
Hello
May be the example below solve your question.
root@notebook:/tmp# cat names.txt
one
two
three
four
five
root@notebook:/tmp# cat test.sh
#!/bin/bash
COUNT=1
while read linein
do
if [[ $COUNT -eq $1 ]] then
echo $linein
exit 0
fi
COUNT=$(( $COUNT + 1 ))
done
Example:
root@notebook:/tmp# ./test.sh 3 < names.txt
three
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.