De: "Himanshu Shekhar" <irm2015...@iiita.ac.in> > Also, I would love to know about good sources to learn and practice > Bash. I followed "The Linux Command Line by William E. Shotts".
Chris F A Johnson has written two books on the subject. Haven't read them but he used to be a regular on comp.unix.shell and he seems to know what he's talking about. /Shell Scripting Recipes: A Problem-Solution Approach/ http://cfajohnson.com/books/cfajohnson/ssr/ /Pro Bash Programming: Scripting the GNU/Linux Shell/ http://cfajohnson.com/books/cfajohnson/pbp/ > > 6) Lots of variable references without double quotes around them, > > EG when calling configure_apt(). What if, say, the password > > contains white space or "?" or "*" or "[" ? > > Please tell me about how to read special characters as @, ? etc. in > password, as @ is the point after authentication where IP starts. I'm not sure I understand the question. I don't expect read to have problems with occurrences of "@" or "?" in its input (but see its -r option). The problem is not stuffing shell metacharacters into a variable, it's what happens when you reference that variable. Suppose variable v contains "*" (an asterisk). Compare the output of echo "$v" and that of echo $v Or set v to "a b" then contrast the result of mkdir "$v" with mkdir $v The explanation is that when you write a command line like cmd $v the shell splits the value of v into words, performs pathname expansion on each word and uses the result of that as the arguments to cmd. You might intend to pass one argument to cmd but you may end up passing zero, two or a thousand. Sometimes, that is what you want. But usually what you want is to pass one argument equal to the value of v. The syntax for that is : cmd "$v" This also applies to constructs like if [ condition ]. When someone writes if [ $variable = "constant" ] there's a high probability that he or she really means if [ "$variable" = constant ]