How to pass whole string also with quotation marks.
#!/bin/bash
my_name="My Value"
function abc(){
a=$1
echo $a
}
abc $my_name
This gives :
My
How to get the value as :
"My value"
also with quotation marks
How to pass whole string also with quotation marks.
#!/bin/bash
my_name="My Value"
function abc(){
a=$1
echo $a
}
abc $my_name
This gives :
My
How to get the value as :
"My value"
also with quotation marks
Try enclosing in quotes instead of abc $my_name
abc "$my_name"
If you want quotes in your output too then try defining as:
my_name="\"My Value\""
and then type:
abc "$my_name"
The easiest way to do this is to pass your argument within single quotes. This will consider your whole argument as a single string. Try this:
#!/bin/bash
my_name='"My Value"'
function abc(){
a=$1
echo "$a"
}
abc "$my_name"