[linux-help] Re: Dollar Arguments
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Saturday 01 July 2006 15:25, Tom Hull wrote:
> Bruce Bales wrote:
> > I can find what is contained in $HOME or $PATH by using the command echo
> > $HOME or echo $PATH. But I often run into other arguments preceded with
> > a "$" which I can't decipher with echo; as in the yum repos where it uses
> > $basearch and fc$releasever. I know basearch is probably i386 or i586
> > and fc$releasever is fc5, but often I don't know what is hidden and echo
> > usually doesn't help. google seems to ignore the "$".
> >
> > Is there a way to retrieve this information or a file where it is stored?
> > bruce
>
> sounds like those are just ordinary shell variables. somewhere before they
> are used there should be a statement that sets them; e.g.:
>
> basearch=i386
>
> or
>
> basearch=`uname -m`
>
> which can also be written
>
> basearch=$(uname -a)
>
> unless there's an export statement, those variables only exist within
> the scope of the /bin/sh program that runs the script. an export statement
> looks like:
>
> export basearch
>
> exported variables are inherited by programs run by the shell, including
> other shell programs. those variables are accessible through the
> environment; see getenv(3)
>
> you'll also see references to shell variables written with braces, e.g.:
>
> fc${releasever}
>
> there are several variants on this which are useful for shell programmers.
>
> some shell variables are set up by your login shell and exported, so they
> are effectively everywhere and easy to check as you note above -- $HOME
> and $PATH are two. you can get a list of all active shell variables by
> running:
>
> set
>
> to find out what's going on inside a shell script, you can run the whole
> shell script with execution trace on:
>
> sh -x -c "command"
>
> if you only want to debug a small part of the script, you can edit the
> script to turn execution trace on/off by surrounding the part of interest
> with these commands:
>
> set -x
>
> set +x
Should this be sh -x and sh +x ??
>
> the -x flag will have already expanded any shell variables. the -v flag
> does a similar trace, but as the command lines are read, so the variable
> names are present there. you can combine these.
Thanks Tom. The set command gives me much of what I have been wondering about
for years. It listed 71 variables.
Looking at /etc/yum, where the $basearch and $releasever are used didn't show
any assignments. I tried to grep for them and found they are used a lot, but
not assigned here.
[bruce@blacky etc]$ grep -Hr "basearch" yum* |wc
59 240 6026
[bruce@blacky etc]$ grep -Hr "basearch=" yum* |wc
0 0 0
[bruce@blacky etc]$ grep -Hr "releasever" yum* |wc
70 270 7070
[bruce@blacky etc]$ grep -Hr "releasever=" yum* |wc
0 0 0
[bruce@blacky etc]$
(I also did a visual search and found no assignments.) I'll try to dig into
some of the python code associated with yum.
Since these variables are used in a configure file and not a shell script I
can't see how to use the sh -x -c .
bruce
-- This is the linux-help@xxxxxxxxx list. To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi
|
|