problem in assigning value to variable have value fo other variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in assigning value to variable have value fo other variable
# 8  
Old 04-25-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
# 9  
Old 04-25-2012
Code:
# cat justdoit
echo -n "ENTER DATE "
read value
s=1;last=$value
## if your value contains "i" in the front of your value then --> last=$(echo $value|sed 's/^.//')
value=$(while [ $(( last -= 1 )) -gt -1 ] ; do
awk -vs=$s 'BEGIN{printf "%02d,",s}';((s++));done|awk '{sub(/^/,"\"{");sub(/,$/,"}\"")}1')
echo $value

Code:
# ./justdoit
ENTER DATE 11
"{01,02,03,04,05,06,07,08,09,10,11}"

regards
ygemici
# 10  
Old 04-25-2012
dear ygemici

the o/p is like this

Code:
-n ENTER DATE
22
new_char[6]: s++: Expression is not complete; more tokens expected.
"{01}"

Moderator's Comments:
Mod Comment Link: How to use [code] tags

Last edited by Scrutinizer; 04-25-2012 at 07:06 AM.. Reason: code tags
# 11  
Old 04-25-2012
Quote:
Originally Posted by sagar_1986
dear ygemici

the o/p is like this

Code:
-n ENTER DATE
22
new_char[6]: s++: Expression is not complete; more tokens expected.
"{01}"

Moderator's Comments:
Mod Comment Link: How to use [code] tags
what is your o.s platform and shell?

try like this..
Code:
echo -n "ENTER DATE "
read value
s=1;last=$value
## if your value contains "i" in the front of your value then --> last=$(echo $value|sed 's/^.//')
value=$(while [ $(( last -= 1 )) -gt -1 ] ; do
awk -vs=$s 'BEGIN{printf "%02d,",s}';let s=s+1;done|awk '{sub(/^/,"\"{");sub(/,$/,"}\"")}1')
echo "$value"


Last edited by ygemici; 04-25-2012 at 07:47 AM..
This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem assigning cmd output to variable then using in IF statement

Hi, I'm using the bourn shell on a Sun Solaris Unix system. I am relatively new to UNIX scripting so please bear with me... I'm having a couple issues: 1) I need to have a variable $FSIZE set with the output of a command each time the script runs. (the command looks for a file and... (8 Replies)
Discussion started by: dqrgk0
8 Replies

2. Shell Programming and Scripting

problem in assigning variable

suppose in my script i have written a1=2 a2=4 read option # I directly want to see the value of a1 or a2 (i:e; 1 or2 )depending upon i/p given like a1 or a2 to option var.so what should i give .Suppose if I give a1 to option then how can I see the value. echo $$option --- doesn't work pls... (3 Replies)
Discussion started by: maitree
3 Replies

3. Shell Programming and Scripting

problem in assigning substr to a variable inside awk

Hi All, I have a fixed-width datafile from which i need to extract value/string starting from some position to the specified length in each of the lines. awk '{print substr($0,x,y)}' datafile --- is working fine but awk 'BEGIN{a=0}{a=substr($0,x,y);print $a}' datafile ---is giving... (3 Replies)
Discussion started by: loggedin.ksh
3 Replies

4. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

5. Shell Programming and Scripting

Assigning value to a variable

Is there any difference between: set variable=39 and variable=39 (1 Reply)
Discussion started by: proactiveaditya
1 Replies

6. Shell Programming and Scripting

Assigning value to a variable

can we make a global variable and store character values and add other values to that variable ?? for example a="hello, John" and can we add value ". How are you? so a can have "hello, John. How are you?" can someone help me?? (2 Replies)
Discussion started by: bonosungho
2 Replies

7. Shell Programming and Scripting

Problem with assigning output of grep + awk to a variable

Hi All, I am getting the output for the following command when i run it on the unix console. --------------------------- grep `whoami` /etc/passwd | awk '{print ($1);}' | cut -d ":" -f3 ---------------------------- But i made it into a script and tried to print the variable, its... (5 Replies)
Discussion started by: meheretoknow
5 Replies

8. Shell Programming and Scripting

assigning a variable

hi all, in ksh, how do i assign the output of a find command to a variable, e.g am trying something like this : totalNoFiles=$(print find ./ -name "SystemOut*.log"); but when i echo $totalNoFiles it displays find ./ -name "SystemOut*.log" instead of the total number of... (2 Replies)
Discussion started by: cesarNZ
2 Replies

9. Shell Programming and Scripting

problem assigning values to variable

Date of Request: 20080514 10:37 Submitted By: JPCHIANG i want to get the value "JPCHIANG" only in read a file, however, when i do this: name=`"$line"|cut -d " " -f8` it display all the line and append 'not found' at the end of the statement the $line is actually a variable in a... (2 Replies)
Discussion started by: finalight
2 Replies

10. Shell Programming and Scripting

Assigning a value to variable

Another newbie to Unix scripting Q.. How do you assign a value resulting from a command, such as awk, to a variable. I am currently trying:- $awk '{print $1}' file1 > variable1 with no change to $variable1. The line: $awk '{print $1}' file1 does print the first line of the... (3 Replies)
Discussion started by: sirtrancealot
3 Replies
Login or Register to Ask a Question