![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX Desktop for Dummies Questions & Answers Questions regarding GNOME, KDE, CDE, Open Office, etc go here. All UNIX and Linux Newbies Welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Inserting variables from 2 files to create 1 file | rochitsharma | UNIX for Advanced & Expert Users | 1 | 03-17-2008 07:33 AM |
| script to create multiple instances of a user account across LPAR's | kcampbell | Filesystems, Disks and Memory | 1 | 10-19-2006 07:42 PM |
| Pass multiple variables to SQL script | jagannatha | Shell Programming and Scripting | 1 | 10-25-2002 06:45 AM |
| multiple variables | micromicrin | Shell Programming and Scripting | 1 | 03-19-2002 07:47 PM |
| multiple DISPLAY variables | QUartz Ite | UNIX for Advanced & Expert Users | 3 | 10-08-2001 06:45 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
trying to create a script with multiple variables...
I have created a script that prompts the user to enter three variables that are seperated by a space as the delimiter.
It then performs a command 3 seperate times for each variable entered. I want the script to llow the user to enter as many variables as they may like and the script to perform the commandwith each variable entered, each time. the scripts promt starts as example of script: read AP1 AP2 AP3 {command + $AP1} {Command + $AP2} {Command + $AP3} they are later used as $AP1 $AP2 $AP3 How can I change this with one read command that will use a loop to repeat the command to each variable entered? Thank you for you help in advance. italy87 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
use an array - note the "command" line will not work, it's an example:
Code:
#!/bin/ksh
echo "enter stuff \c"
read dummy
set -A array $dummy
let i=0
while [[ $i -lt ${#array[*]} ]]
do
<command> ${arr[i]}
let i=$i+1
done
|
|
#3
|
|||
|
|||
|
Hello, I couldn't help wonder how I would do it in bash. This one lets the user enter all arguments first, one line at a time, then operates on the arguments.
It is more verbose than it should be, only to show usage of arrays... replace "echo "executing command"..." etc with Your actual command. Code:
#!/bin/bash
echo Enter arguments, just press enter when finished.
cnt=0
while [ true ]; do
echo -n "Enter argument $(($cnt+1)): "
read x[$cnt]
[ "${x[$cnt]}" == "" ] && break
cnt=$(($cnt+1))
done
echo Processing $cnt arguments
cnt=0
while (($cnt < ${#x[@]}-1 ))
do
echo "executing command on argument $(($cnt+1)) which is: ${x[cnt++]}"
done
#echo ${x[@]}
|
|
#4
|
|||
|
|||
|
OK, I should provide more info. first I am running in ksh.
I have a file with one line of a series of words that are three letters long, using s space as the delimiter. I want to run a script which will retrieve those words and assign them to a variable, which i can run with my command in a loop until each word has been used, individually each time in the command until each three letter word has been used. the file looks like this: AIN OTB ALK SJA ALS HAH INA (etc..) I want to run the command with all three letter word individually. The commands i want to perform is already designed. I just need to insert the words in the command in a loop to do it each tmie. note the file may change with the count of words but it will always be three letter words. therefore it has to count the words each time it is run. i was thinking I would cat the file, pipe it to a wc -w and use that as the count for how many time to perform the loop. (I.e. wordct="cat <filename> | wc -w") with this variable I have a defined count of how many words each time. I hope this helps. |
|
#5
|
|||
|
|||
|
reading them as one variable and the segregating will help
Last edited by raman1605; 03-21-2008 at 11:02 AM. Reason: Took wrong meaning of the query |
|
#6
|
|||
|
|||
|
any suggestions on how to do that?
|
|||
| Google The UNIX and Linux Forums |