I am trying to write a script to imitate this script output in linux bash:
(bob@server:~> filesize
Enter a file name (or q! to stop): fee
fee uses 123 bytes.
Enter a file name (or q! to sp): fi
There is no file called fi.
Enter a file name (or q! to stop): foe
foe uses 9802 bytes.
Enter a file name (or q! to stop): q!
bob@server:~>)
My script looks like this (the script name is filesize):
#!/bin/bash
while true; do
read -p "Enter a filename (Or q! to stop) : " X
case $X in
[q!]* ) exit;;
* ) echo "$X uses "$(wc -c <$X)" bytes";./filesize;;
esac
done
After I type anything other than q! and it reads $X uses $(wc -c <$X), I have to type q! twice to make the command exit.
How do I make it so that I only have to type q! once to make the command exit, instead of typing it the multiple times that I read a size of a file?
./filesizein your script, which is pointless. You're already in a infinite loop until you break out. Just remove that.[q!]is that it matches a single character which is eitherqor!.