01-31-07 06:29 AM
<ashley73@gmail.com> wrote:
>What I currently have is:
>if [ "$USER" = aselive ] ; then
>. /live/.profile
>elif [ "$USER" = aselive8 ] ; then
>. /live8/.profile
>fi
>I would like to reduce this to a single line by concatenating the
>$USER variable and reading the relevant .profile,
You mean concatenating the path to a substring of the $USER variable.
USERBASE=$(expr substr $USER 4 99)
. /$USERBASE/.profile
or just
. /$(expr substr $USER 4 99)/.profile
If you're using a shell other than bash, you can use backticks instead of $(
),
and if you don't have gnu expr, you can find other commands to do the same
thing.
>echo $USER | awk '{ print substr($0,4) }'
write it as
. /`echo $USER | awk '{print substr($0,4) }'`/.profile
and it'll work.
>What would be the best way to achieve this?
There is no best way. There's lots of adequate ways. Welcome to shell
scripting - if you want a good way to do stuff like this without spawning
dozens of tiny little programs, use a more powerful language (perl, ruby,
python, etc.).
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
[ Post a follow-up to this message ]
|