How to assign * asterisk to variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to assign * asterisk to variable?
# 1  
Old 10-26-2010
How to assign * asterisk to variable?

How can I assign asterisk to variable
I have try a="\* " but I was not succesful Smilie
any idea ?
thanks

Last edited by radoulov; 10-26-2010 at 09:54 AM.. Reason: Added icode tags.
# 2  
Old 10-26-2010
Code:
% v=*; echo "$v"
*

This User Gave Thanks to radoulov For This Post:
# 3  
Old 10-26-2010
did you mean $* ?
or
Code:
var='*'
echo "$var"

or
Code:
var="*"
echo "$var"


Last edited by ctsgnb; 10-26-2010 at 10:06 AM..
# 4  
Old 10-26-2010
var="\*"
echo $var
---------------------
or
var='\*'
echo $var
# 5  
Old 10-26-2010
Radoulov is right. Just use:
Code:
var=*

# 6  
Old 10-26-2010
Quote:
Originally Posted by rainboisterous
var="\*"
echo $var
---------------------
or
var='\*'
echo $var
Actually, it's the opposite: you don't need the first pair of quotes (it makes no harm, but as filename generation/globbing is not performed in this context, they are redundant) and you need to quote the second statement (because in that context in most shells the pattern is subject to filename generation):

Code:
var=*
echo "$var"

This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies

2. UNIX for Beginners Questions & Answers

Need to pass variable in a command and assign value to a variable

Hello All, Hope you're doing well ! I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted. header_date_14=$(m_dump... (8 Replies)
Discussion started by: ektubbe
8 Replies

3. Shell Programming and Scripting

Need to use asterisk in variable

Hi All, I am having a challange to pass the asterisk in the variable. Basically, I am writing a shell script to check if a marker file exists but when I am assigning the varialbe it cannot use the wildcard asterisk as expected, therefore, my program is always outputs "Marker file is not... (4 Replies)
Discussion started by: express14
4 Replies

4. Shell Programming and Scripting

Shell assign variable to another variable

How can I assign a variable to an variable. IE $car=honda One way I can do it is export $car=honda or let $car=2323 Is there any other ways to preform this task (3 Replies)
Discussion started by: 3junior
3 Replies

5. AIX

Replace string with asterisk(*) in variable

I was trying to replace a string ( for eg - @@asterisk@@ to * ) in variable using cat $INFILE | while read LINE do stmt1=`echo $LINE | sed 's/@@asterisk@@/\*/g'` stmt=$stmt' '$stmt1 stmt2=`echo $LINE` STATEMENT=$STATEMENT' '$stmt2 done echo 'Statement with sed -- > '... (5 Replies)
Discussion started by: Vaddadi
5 Replies

6. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

7. Shell Programming and Scripting

Assign this to a variable....

bash-3.00$ /usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4 == "tcp*.21")print $5}' *.* bash-3.00$ A=` /usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4 == "tcp*.21")print $5}'` bash-3.00$ echo $A db2_lastdone.bkp As you can see ,after running command i get *.* in return but the same... (5 Replies)
Discussion started by: ak835
5 Replies

8. Shell Programming and Scripting

How to ignore * (asterisk) in a variable

I am using a shell script to read SQL statements stored in a DB2 table and write them out to a file. The problem I have is that some SQL statements have an "*" in them which gets resolved as the list of files in the current directory when I run the script. How can I prevent the "*" from being... (7 Replies)
Discussion started by: bradtri2
7 Replies

9. Shell Programming and Scripting

passing asterisk to a script as variable

I'm writing a script that will ssh to a number of hosts and run commands. I'm a bit stumped at the moment as some of the commands that I need to run contain wildcards (i.e. *), and so far I have not figured out how to escape the * character so the script doesn't expand it. More specifically, here's... (9 Replies)
Discussion started by: GKnight
9 Replies
Login or Register to Ask a Question