|
Prev: bash: best way to do tenary operator??
Next: china wholesale cheap nike shoes,cheap nike,cheap nikes,nike jordans sneaker's,cheap nike air force 1s
From: Fox on 18 Apr 2008 13:59 My code is as follows: ---------------------------- #!/bin/bash echo -n Where do you want to install ? read new_install_dir cd ${new_install_dir} ---------------------------- If my input is /home/fox/install - it works but if user inputs ~/ install it dump with the following error code: ../script/install: 6: ~/install: not found how can i fix this error? TIA
From: Chris F.A. Johnson on 18 Apr 2008 14:08 On 2008-04-18, Fox wrote: > My code is as follows: > > ---------------------------- > #!/bin/bash > echo -n Where do you want to install ? > read new_install_dir > > cd ${new_install_dir} > ---------------------------- > > If my input is /home/fox/install - it works but if user inputs ~/ > install it dump with the following error code: > ./script/install: 6: ~/install: not found > > how can i fix this error? So long as there are no spaces in the input: eval "cd $new_install_dir" -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence
From: Fox on 18 Apr 2008 14:30 On Apr 18, 11:08 pm, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote: > On 2008-04-18, Fox wrote: > > My code is as follows: > > > ---------------------------- > > #!/bin/bash > > echo -n Where do you want to install ? > > read new_install_dir > > > cd ${new_install_dir} > > ---------------------------- > > > If my input is /home/fox/install - it works but if user inputs ~/ > > install it dump with the following error code: > > ./script/install: 6: ~/install: not found > > > how can i fix this error? > > So long as there are no spaces in the input: > > eval "cd $new_install_dir" thanks a lot; it worked like a charm. I'd like to know why we need to use eval command? It is not required for other operation such as rmdir. Is this a cd specific or some sort of pitfall built into bash shell. > > -- > Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) > ===== My code in this post, if any, assumes the POSIX locale > ===== and is released under the GNU General Public Licence
From: Dan Mercer on 18 Apr 2008 17:39
"Fox" <fox(a)foxmail.in> wrote in message news:2624a906-7074-4cb6-a690-488d2182ed3e(a)a9g2000prl.googlegroups.com... On Apr 18, 11:08 pm, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote: > On 2008-04-18, Fox wrote: > > My code is as follows: > > > ---------------------------- > > #!/bin/bash > > echo -n Where do you want to install ? > > read new_install_dir > > > cd ${new_install_dir} > > ---------------------------- > > > If my input is /home/fox/install - it works but if user inputs ~/ > > install it dump with the following error code: > > ./script/install: 6: ~/install: not found > > > how can i fix this error? > > So long as there are no spaces in the input: > > eval "cd $new_install_dir" thanks a lot; it worked like a charm. I'd like to know why we need to use eval command? It is not required for other operation such as rmdir. Is this a cd specific or some sort of pitfall built into bash shell. Neither. It's the way the shell works. Tilde expansion occurs before variable expansion. So the shell sees a literal ~, not the HOME directory. Eval causes the line to be reparsed after variable expansion. Dan Mercer > > -- > Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) > ===== My code in this post, if any, assumes the POSIX locale > ===== and is released under the GNU General Public Licence |