bash scripts: using ~<username> - Questions
This is a discussion on bash scripts: using ~<username> - Questions ; When typed at the bash prompt, ~ is expanded to the
home directory of the specified user. Whay cannot I use this
construct in scripts? Or, if I can, then how?...
-
bash scripts: using ~<username>
When typed at the bash prompt, ~ is expanded to the
home directory of the specified user. Whay cannot I use this
construct in scripts? Or, if I can, then how?
-
Re: bash scripts: using ~<username>
["Followup-To:" header set to comp.os.linux.misc.]
Angel Tsankov staggered into the Black Sun and said:
> When typed at the bash prompt, ~ is expanded to the home
> directory of the specified user. [Why can'] I use this construct in
> scripts? Or, if I can, then how?
Works for me:
clairissa:~$ cat temp.sh
#!/bin/bash
cd ~guest
pwd
clairissa:~$ ./temp.sh
/home/guest
....maybe you'd better post an example of how it doesn't work for you,
with the exact command that's getting executed. Remember, when
debugging shell scripts, "set -x" can give you a whole lot of
information.
--
"Dreams? Best leave dreams to those that can afford them."
--Aunt Cordelia, _Wizard and Glass_, Stephen King
There is no Darkness in Eternity/But only Light too dim for us to see
-
Re: bash scripts: using ~<username>
"Angel Tsankov" writes:
> When typed at the bash prompt, ~ is expanded to the home
> directory of the specified user. Whay cannot I use this construct in
> scripts? Or, if I can, then how?
Dunno what you ask really, but maybe that's what you want:
#v+
FOO_HOME="$(echo ~foo)"
#v-
or maybe even:
#v+
homedir () { eval echo "~$1"; }
FOO_HOME="$(homedir foo)"
#v-
In general, as was noted already, you can use things like:
#v+
cd ~foo
mv file ~bar/file
# ... and so on
#v-
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +------ooO--(_)--Ooo--
-
Re: bash scripts: using ~<username>
On 2006-09-17, Angel Tsankov wrote:
> When typed at the bash prompt, ~ is expanded to the
> home directory of the specified user. Whay cannot I use this
> construct in scripts? Or, if I can, then how?
dir=~user
Not:
dir="~user"
--
Chris F.A. Johnson, author |
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
-
Re: bash scripts: using ~<username>
On Sun, 17 Sep 2006, Angel Tsankov wrote:
> When typed at the bash prompt, ~ is expanded to the home directory
> of the specified user. Whay cannot I use this construct in scripts? Or, if I
> can, then how?
Why not use $HOME instead?
>
>
-
Re: bash scripts: using ~<username>
On 2006-09-18, Whoever wrote:
>
>
> On Sun, 17 Sep 2006, Angel Tsankov wrote:
>
>> When typed at the bash prompt, ~ is expanded to the home directory
>> of the specified user. Whay cannot I use this construct in scripts? Or, if I
>> can, then how?
>
> Why not use $HOME instead?
Because that's not the same. $HOME is one's own home directory;
~user is user's home directory.
--
Chris F.A. Johnson, author |
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence