Which assignment syntax to use when?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Which assignment syntax to use when?
# 1  
Old 06-19-2013
Which assignment syntax to use when?

Hi,

Lately, I have seen 2-3 variable assignment commands - set, setenv, export. What is the difference between them? Which one to use when? Really appreciate for the help...

regards,
juzz4fun
# 2  
Old 06-19-2013
I suggest you read the man page of the shell which you didin't tell us any specifics about.

"export" is not an assignment, it just marks an already assigned vaiabl for export when a new shell environment is invoked.

"setenv" is a csh assignment command.

"set" in most cases (with the exception of "set --", which deletes positional variables in Bourne-shell descendants and "set -A" in ksh) just lists all the assigned variables, not assigns them.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 06-19-2013
sh, bash and ksh sets variables with just the "=" sign (i.e., aa=boo) while csh and tcsh sets variables with set at the beginning of the line (i.e., set aa = boo) ...

variables are usually local to the subshell the script/user is working in ... if a variable is being set by one shell and needed to be used in another shell, the variable must be exported or shared from the local shell and imported by the other shells ...

sh, bash, and ksh uses export while csh and tcsh uses setenv to share the variables from the local shell ...


-------------

forgot about the info on set that bakunin mentioned ... guess i need to get reading again ...
This User Gave Thanks to Just Ice For This Post:
# 4  
Old 06-19-2013
Thanks a ton, JustIce and bakunin ... you are superb !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable Assignment

Hi I am facing a problem. export local_folder=/opt/app/ cd /opt/app/abc/ abcversion="abc*" (abcga5 is inside /opt/app/abc/) echo $abcversion (it echoes the correct version as abcga5 ) Now when I reuse the value of abcversion for a below path: export... (6 Replies)
Discussion started by: ankur328
6 Replies

2. UNIX for Dummies Questions & Answers

Need a little help with assignment

Hello all im currently working on this assignment and a little stump on how to check for an argument heres the instructions: Step 4: Modify your script so that if there is an argument called TestError you display the following error message with your usage statement. TestError found Example:... (1 Reply)
Discussion started by: bsn3971
1 Replies

3. Homework & Coursework Questions

Help Assignment !! :D

Q-1 Write a shell script in Unix that lists files from your current working directory · By modification time when called with lm · By access time when called with la. By default, the script should show the listing of all the files in the current directory. Q-2 Write a shell script which... (1 Reply)
Discussion started by: Vishank Parikh
1 Replies

4. Shell Programming and Scripting

Help Assignment !! :D

Q-1 Write a shell script in Unix that lists files from your current working directory · By modification time when called with lm · By access time when called with la. By default, the script should show the listing of all the files in the current directory. Q-2 Write a... (1 Reply)
Discussion started by: Vishank Parikh
1 Replies

5. Homework & Coursework Questions

Assignment Help

1. List commands to create the directory hierarchy $HOME/a/b/c in vi to replace all occurences of TMP with tmp in lines 1 through 10 in vi to replace first occurence of CPU_file with DISK_file at line 15 2. Explain with a very simple example, usage of "ls -a" 3. What do the... (2 Replies)
Discussion started by: jessesaini
2 Replies

6. Shell Programming and Scripting

RE value assignment

Hi all How do I assign a pattern to a variable after a match is found using a regular expression in PERL? For example using a regular expression (RE) and matching as given if ($_ =~ /(?:\s*+\s*,)*\s*+\s*/) I want to assign the pattern matched by the RE to a variable. e.g. given the... (4 Replies)
Discussion started by: my_Perl
4 Replies

7. Shell Programming and Scripting

Syntax error on variable assignment

Hello all, I have "inherited" a Korn shell script I'm supposed to maintain, and running a "sh -n" on it, I got this syntax error: script.sh: syntax error at line 63: `OB_DEVICE=$' unexpected The line in cause is the first occurence of the usage of perl one-liners. The whole line: ... (2 Replies)
Discussion started by: AdrianM
2 Replies

8. What is on Your Mind?

New Assignment

All Sys Administrators, With due respect I would like to know what should be BEST Things to do when LEAVING one job , and what Precaution MUST be taken while taking over new JOB?? Please Discuss in detail the STEP to be taken for both the TIME ?? (3 Replies)
Discussion started by: vakharia Mahesh
3 Replies

9. UNIX for Dummies Questions & Answers

how to do my assignment?????

my lecturer want to do an assignment about telnet server..first, he want us to download the telnet server..then he want we do about copy files and share files by using the telnet server....what is that??? and one more thing is how to do 'ping'???? (1 Reply)
Discussion started by: amelia
1 Replies

10. UNIX for Dummies Questions & Answers

@ in a variable assignment

Hello Everybody, Does anyone know what the @ symbol means in a csh script, if used with a variable assignment as below @ line = 1 why not just use.... set line=1 Many thanks rkap (1 Reply)
Discussion started by: rkap
1 Replies
Login or Register to Ask a Question