I am working on a script that prompts a user name and creates a list in a username.dat file. Furthermore, I have created a sorted_username.dat file. My question is this: My script uses the word "finished" != finished to break the while loop. How can I avoid having the word "finished" show up in my dat files? Many thanks!
Could you post a code sample? This would make it clearer what it exactly is you're trying to achieve.
Otherwise, don't use the word finished as value in your script ....
variable=" "
echo $variable > name.dat
while [ "$variable" != "finished" ]
do
echo "Please enter your name (type finished when done)"
read variable
echo $variable >> name.dat
sort < name.dat > sorted_name.dat
echo $variable
done
I am a finance guy trying to learn UNIX. Specifically, I am trying to accomplish a few things here.
1) I want the main screen to show the whole list of names typed in during the session (currently as written the main screen only shows the last name typed in).
2) The way this program is written, the sorted_name.dat file shows a blank line at the top of the list due to the initialization of the variable. I would like to eliminate that first blank line at the top of the list through, perhaps, an adjustment of my code.
3) As you can see, I chose finished as the way to quit the loop. It could be any word that quits the loop. I am trying to find a way to NOT have the != string show up in my lists (on the main screen or on the .dat files.)
Thank you so much.
You can use:
variable=" "
echo $variable > name.dat
while [ "$variable" != "finished" ]
do
echo "Please enter your name (type finished when done)"
read variable
if [ $variable != "finished" ] then
echo $variable >> name.dat
sort < name.dat > sorted_name.dat
fi
echo $variable
done
Good luck.
while [ 1=1 ];
do
printf "Please enter your name: (qQ) to quit: "
read choice
case $choice in
"Q"|"q" ) break;;
esac
printf "$choice\n" >> name.dat
done
sort name.dat > sorted_name.dat
Cali,
I appreciate your help. I tried running this script you sent me, but when I run it I get a syntax error at line 12...regarding the fi. Could you please help me a little more and please let me know what exactly the fi means/does? Also, will this script eliminate the blank entry at the top of my .dat files?
Thank you very much.