LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   assigning value * to variable problem (http://www.linuxquestions.org/questions/programming-9/assigning-value-%2A-to-variable-problem-4175445350/)

coolpraz 01-13-2013 01:03 AM

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 *

colucix 01-13-2013 03:54 AM

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.

konsolebox 01-13-2013 04:41 AM

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.


All times are GMT -5. The time now is 08:23 AM.