Variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable
# 1  
Old 09-13-2011
Java Variable

Code:
tmpf0="temp0".$$
tmpf1="temp1".$$
tmpf2="temp2".$$

Hi !

can anyone explain what does mean by the above expressions

i mean why double quotes has been used along with dot and dollar sign?

Regards,
TJ

Last edited by vbe; 09-13-2011 at 10:43 AM.. Reason: Please use code tags for any code or data
# 2  
Old 09-13-2011
I don't see a reason - you could try just without and will have the same output. Looks like somebody wanted to define some temporary file names. The $$ will contain the process id (PID) of the shell the script is being executed in. Every time the script is started anew, the PID will be different.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 09-13-2011
If you were parano´d you would do such thing to be sure to affect a string (between the double quotes...) dot PID to a variable...Smilie
This User Gave Thanks to vbe For This Post:
# 4  
Old 09-13-2011
tmpf0=temp0.$$ tmpf1=temp1.$$ tmpf2=temp2.$$

tmpf0="temp0".$$ tmpf1="temp1".$$ tmpf2="temp2".$$

it means both will produce same results?

and why to include dot(.) between temp0 and $$ (temp0.$$)

and can you explain to me why we include the following line at top of every file?

#!/bin/sh

and kindly explain at low level because i'm new to shell scripting otherwise i would have not asked such trivial questions.

Thanks in advance
# 5  
Old 09-13-2011
Quote:
it means both will produce same results?
Why not try it?

Code:
echo temp1.$$
echo "temp1".$$

Code:
and why to include dot(.) between temp0 and $$ (temp0.$$)

No particular reason. It's just a randomly generated file name.
Quote:
and can you explain to me why we include the following line at top of every file?

#!/bin/sh
So that when the script is run, it uses /bin/sh to process it. A PERL script might use #!/usr/bin/perl. If you do sh ./script it should effectively run it the same way without a #! being necessary but if you want the script to be capable of running all by itself, the #! line is a good idea.
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 09-14-2011
Java

thank you corona688 i was looking for such an answer...

Kind Regards,

TJ

---------- Post updated at 08:28 AM ---------- Previous update was at 02:42 AM ----------

well Corona i understood your point but it is not exactly as you said "courtesy"

for example if i run the code with out including #!/bin/sh it also work so why to include it? the following code is working fine whether i include #!/bin/sh at the top or not

value1="2"
value2="10"

result=`expr $value1 + $value2`
echo $value1 + $value2 = $result

i hope you have understood my point now
# 7  
Old 09-14-2011
Quote:
Originally Posted by ourned
well Corona i understood your point but it is not exactly as you said "courtesy"

for example if i run the code with out including #!/bin/sh it also work so why to include it?
Without the #!, the OS will assume the default, /bin/sh.

But a UNIX system may have many languages available. If a script needs /bin/bash, /bin/ksh, /bin/csh, /bin/zsh, /usr/bin/perl, /usr/bin/awk, or anything else, it can put it after #! and run the script using that instead.

It's traditional to put #!/bin/sh up top even for scripts which don't need it. This is safer -- it's not impossible that a programmer might write a comment with #!, which would mess up the script if it didn't have #!/bin/sh first. If there's weird characters at the end of the line, having a #! will cause it to quit with 'bad interpreter' (since it can't find the filename /bin/sh^M) instead of trying to run invalid code inside a valid shell. It also lets a human instantly tell scripts apart from plain text files.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

2. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

3. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

4. Shell Programming and Scripting

Variable not found error for a variable which is returned from stored procedure

can anyone please help me with this: i have written a shell script and a stored procedure which has one OUT parameter. now i want to use that out parameter as an input to the unix script but i am getting an error as variable not found. below are the unix scripts and stored procedure... ... (4 Replies)
Discussion started by: swap21783
4 Replies

5. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

6. Shell Programming and Scripting

Split variable length and variable format CSV file

Dear all, I have basic knowledge of Unix script and her I am trying to process variable length and variable format CSV file. The file length will depend on the numbers of Earnings/Deductions/Direct Deposits. And The format will depend on whether it is Earnings/Deductions or Direct Deposits... (2 Replies)
Discussion started by: chechun
2 Replies

7. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

8. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

9. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies

10. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies
Login or Register to Ask a Question