LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-13-2013, 12:03 AM   #1
coolpraz
Member
 
Registered: Feb 2010
Posts: 35

Rep: Reputation: 0
assigning value * to variable problem


hi
im writting script where in one point i got and unexpected result
here example

Code:
ASDF="*"
echo $ASDF
This display file and folder of the same folder where script is or from script is executed. I want to just display *
 
Old 01-13-2013, 02:54 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Just use double quotes around the value, as you did in the variable assignment:
Code:
echo "$ASDF"
Double quotes don't prevent variable substitution, but protect the asterisk from the filename expansion. Quoted from http://tldp.org/LDP/Bash-Beginners-G...ct_03_03.html:
Quote:
Using double quotes the literal value of all characters enclosed is preserved, except for the dollar sign, the backticks (backward single quotes, ``) and the backslash.
 
Old 01-13-2013, 03:41 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Another way to interpret it is that double quotes create a new string based on its contents and keeps it as is or prevents it from being re-expanded or re-parsed from the outside.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] problem with assigning output of ls command to variable when ls produces error tanasqui Linux - Newbie 5 04-30-2011 05:02 PM
[SOLVED] Problem in assigning value to a variable in shell script. mshforever Linux - Newbie 8 11-30-2010 07:05 AM
Assigning variable is messing up voldemort Programming 1 11-05-2010 02:26 PM
Trouble assigning value to variable with fatsheep Programming 1 11-07-2006 07:44 PM
assigning commands to a variable aunquarra Linux - General 5 01-04-2006 07:58 AM


All times are GMT -5. The time now is 03:55 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration