Results 1 to 6 of 6
Hi all, i have more questions but its all about variables so lets begin
1st, is possible to list all variables ?
Command env display only shell variables, but what ...
- 07-28-2009 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 49
shell variables advanced
Hi all, i have more questions but its all about variables so lets begin
1st, is possible to list all variables ?
Command env display only shell variables, but what if i declared another variable? Command set display more variables but not defined by me.
2nd, what difference is between set and env ?
3rd, lets say i declared variable which contains whitespaces, or i have variable which contains whitespaces for example IFS. When i type echo $IFS i see nothing, so i dont know if is declared or if contain white spaces.
Is possible to write white spaces in C format (\n \r \t ...) ?
4th what is difference between sourcing and exporting variable ?
PS: i saw declaration of IFS in set command (IFS=$' \t\n')
- 07-29-2009 #2Just Joined!
- Join Date
- Jul 2009
- Posts
- 8
1. is possible to list all variables ?
set>/tmp/variables.0
. file-containing-variable-defs
set>/tmp/variables.1
echo "file-containing-variable-defs defined the following:"
cat /tmp/variables.0 /tmp/variables.1 | sort | unit -u
rm /tmp/variables.[01]
2.If you want to use a program in a particular directory that is not in your regular search path (something in /usr/fred, for example), you could add to the search path by entering the following command:
set path = (/usr/fred $path)
env: To display the environment variable which is already set.
If you want to use a program in a particular directory that is not in your regular search path (something in /usr/fred, for example), you could add to the search path by entering the following command:
set path = (/usr/fred $path)
- 08-01-2009 #3Just Joined!
- Join Date
- Jul 2009
- Posts
- 49
1 why did you set> file and then cat<file, this can be done just using set, correct me if i am wrong
- 08-01-2009 #4Just Joined!
- Join Date
- Jul 2009
- Posts
- 58
Wakatana,
I think you're mixing up parameters and settings with environment variables.
# set
...
gives you a list of options/settings that were set to launch that shell environment, these are totally shell dependent. That shell reads them to figure out how to interact with you, for example, your "prompt" is a shell variable. Most of these have a default value and are set when you launch your shell -- obviously they can be overriden.
Environment variables from `# env` are dynamic variables that really don't exist at all, unless you set them. Other programs interact with these, so program xyz can read/set environmental variables to store information.
A good difference is 'prompt' -- you can 'set prompt' and the prompt will change, however `setenv PROMPT` or `PROMPT=xxx` does't.
To answer the questions:
1) 'set' and 'env' at least in csh or tcsh will give you a list of all vars.
2) see above
3) don't declare variables with spaces. Otherwise see ${var} so that it's encompassing.
4) source brings in the results from an external source into your correct program, be it a shell or another script. 'export' tells the current enviornment, that this variable that is set, can be seen/is visible to the shell and other scripts once this script has exited.
- 08-01-2009 #5Just Joined!
- Join Date
- Jul 2009
- Posts
- 49
And what is local and global variables ? What do ypu mean with prompt i did not understand what you mean, thanx
- 08-01-2009 #6Just Joined!
- Join Date
- Jul 2009
- Posts
- 58
There is no such thing as local and global variables. A variable is a variable, it may get its value initially by the shell, an rc file, a script, or manually by the user.
# set prompt .....
vs.
# setenv PROMPT
one sets your shell prompt, one does nothing.


Reply With Quote