subsequently reference variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting subsequently reference variable
# 1  
Old 05-08-2010
subsequently reference variable

Hello,
This is not homework. It is a question that I received on a recent interview for a linux position. Can someone shed some light on the right answer? I got it wrong.


Quote:
Q17: The following line appears in a shell script: "X=$1". How does the script subsequently reference variable X?
a) X
b) $X
c) X$
d) $1
Thanks,

jaysunn
# 2  
Old 05-08-2010
If I understood the question correctly, then I answer b Smilie.
Better question will be "value of the variable X". X is variable. Value of variable is $X.
What was the question ? Maybe a is also correct answer ? Why ? If I like to set new value for the variable then I use only X. The best answer is: question is not well done.
This User Gave Thanks to kshji For This Post:
# 3  
Old 05-08-2010
Quote:
The best answer is: question is not well done.
That is what I had trouble with. I did not understand it correctly. I was told that I got 1 of 4 wrong, however I was not told the answer, or which one I got wrong out of 4. I picked $1 or d. I may of been right. Thats why I need some other opinions.


From the definition.

subsequently
adverb later, afterwards, in the end, consequently, in the aftermath (of), at a later date Subsequently the arrangement was terminated.

I now think I am wrong.
jaysunn

Last edited by jaysunn; 05-08-2010 at 11:30 AM.. Reason: Added definition
# 4  
Old 05-08-2010
The answer is B.

The question starts with the premise of passing a parameter to a script call and assigning the parameter to the variable X. Consider a sample script called test.sh:
Code:
#!/bin/bash     < Tells the BASH shell to execute the script
X=$1            < Assigns the parameter to the variable X
echo $X         < Calls the variable X and echos the contents to the standard output

Execute the script by passing a parameter. The output from the script will look like:
Code:
>test.sh "Hello World"
Hello World

EDIT:
By the way, you can get a lot of information on shell scripting from the Linux Documentation Project's guides for BASH. They are BASH specific, but many of the concepts apply to other shells as well. BASH is generally available on all *NIX systems and is arguably among the most flexible. They are located at the following URLs:
Beginners: http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
Advanced: http://tldp.org/LDP/abs/html/index.html

Last edited by dunkar70; 05-08-2010 at 01:03 PM.. Reason: Adding reference
This User Gave Thanks to dunkar70 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get last reference date

Hi, Could you please help me to get last reference date in Unix, in Unix we maintain SAS7BDAT files. Is there any command or script to get the info, Thank you. (2 Replies)
Discussion started by: subbarao12
2 Replies

2. Shell Programming and Scripting

Perl de-reference code reference variable

Guys, May i know how can we de reference the code reference variable.? my $a = sub{$a=shift;$b=shift;print "SUM:",($a+$b),"\n";}; print $a->(4,5); How can we print the whole function ? Please suggest me regarding this. Thanks for your time :) Cheers, Ranga :) (0 Replies)
Discussion started by: rangarasan
0 Replies

3. Shell Programming and Scripting

Perl: accessing reference to variable inside hash.

Below is hash which contains reference to variables: my %mandatoryFields = ( 1 => \$msgtype, 2 => \$switchtype, 3 => \$card_nbr, 4 => \$natv_tran_type_code, 5 => \$amt_1 ); This... (0 Replies)
Discussion started by: som.nitk
0 Replies

4. Homework & Coursework Questions

undefined reference help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: i know when undefined reference shows up the program is saying it is not link to that function but the problem... (1 Reply)
Discussion started by: mgyeah
1 Replies

5. Shell Programming and Scripting

BASH - Reference external variable name dynamically

Hi there, I have included an external properties file into my BASH script via the 'source' command. I am attempting to dynamically assign a variable in the BASH script, that references the variable name within the external properties file i.e. #!/bin/bash pth=${0%/*} source... (3 Replies)
Discussion started by: mjwoodford
3 Replies

6. Shell Programming and Scripting

Unix Variable Reference and Substitution

I can't seem to make what appears to be a simple substitution. I want to define a list of systems for which daily reports need to be filed systems="systemA systemC systemZ" I then want to run a loop for i in ${systems} Analyze statistics Create the reports mailx (8 Replies)
Discussion started by: mugsymark
8 Replies

7. Shell Programming and Scripting

Reference Variable

Hi! I need to determin the most efficient way to do something (rather simple, I thought). I'm currently echo(ing) a series of menu options, and reading the command input as the number associated with the entry. What I need to do is when the option 1 is selected, that it references a list and... (18 Replies)
Discussion started by: cchaloux
18 Replies

8. Shell Programming and Scripting

How to reference a variable within sed?

Hi all, How can I use sed to perform a substitution if the string that I'm going to substitute is stored in a variable: Let's say: sed 's/abcdefg/good' VS tmp="abcdefg" sed 's/$tmp/good' The second case doesn't work. Guess it's due to the single quotes on the outside. How can I... (1 Reply)
Discussion started by: rockysfr
1 Replies

9. HP-UX

Reference Material

I'm having to write 'C' programs for a group of HP-UX 11.X systems. While I have found many 'C' reference books which I like, none of them reference using 'C' in the UNIX environment. Anyone have any good recommendations for books about 'C' programming under UNIX? Thanks. Chris (0 Replies)
Discussion started by: chrisc@nwark.ne
0 Replies
Login or Register to Ask a Question