Results 1 to 2 of 2
Good day everyone!
I have a part of a script which asks user to input data in it
Code:
#!/bin/bash
rm cell-data
#data to cell-data.txt
echo "Paste data for UPDATE ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-27-2012 #1Just Joined!
- Join Date
- Jul 2012
- Posts
- 9
input to file
Good day everyone!
I have a part of a script which asks user to input data in it
sample dataCode:#!/bin/bash rm cell-data #data to cell-data.txt echo "Paste data for UPDATE correction:" echo "enter \"^\" when done" #getting information for update while read LINE1 do echo $LINE1 >> temp if [ "$LINE1" = "^" ];then break fi done sed 's/\^//g' temp | sed '/^$/d' > update-data
these are for update
77024466663 450
77024466653 350
77024464353 150
and these are for reload
77028476663 250
77028476653 50
77028474353 150
i need to get data for two files
for update
and for reload
how to modify the script to do it????
something like "For update press 1, then enter data and press ^ when done"
than asks again
and to get two files in the endCode:press 1 for update 2 for reload 0 when done # for ex 1 is pressed input for update press ^ save data and go back to previous menu 77024466663 450 77024466653 350 77024464353 150 ^ 1 for update 2 for reload 0 when done # now 2 is pressed input for update press ^ save data and go back to previous menu 77028476663 250 77028476653 50 77028474353 150 ^ 1 for update 2 for reload 0 when done # now 0 is pressed
update and reload
- 07-28-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
you can put the portion of code that gets input into a bash function, then call that function when you need it. just pass the output file to it as an argument. in my example, i pass it as the 2nd argument (the first argument is just a descriptive string).
here's the code:
i'm not exactly sure it does what you want, but hopefully it'll get you along some.Code:get_input() { mode=$1 output=$2 echo "Enter text for \"$mode\":" echo "(press Ctrl+D when done)" [ -f "$output" ] && rm -f $output while read line; do echo $line >> $output done echo "Wrote: $output" sleep 1 } while :; do case $foo in 1) get_input Update '/tmp/update.txt' unset foo ;; 2) get_input Reload '/tmp/reload.txt' unset foo ;; 3) exit 0 ;; *) clear echo "Make a selection: 1. Update 2. Reload 3. Exit " read foo esac done


Reply With Quote
