This question already has answers here:
What's the magic of "-" (a dash) in command-line parameters?
(5 answers)
Closed 3 years ago.
I recently had to use some code that was given to me, and in it the is this line
cat file -
Did someone know what the - mean.
The - means "read from standard input" (this is a POSIX convention). Try this in your shell and you'll see cat repeat everything you type:
$> cat -
Related
This question already has answers here:
Difference between sh and Bash
(11 answers)
Closed 3 years ago.
i am trying to get value of variable by given string:
Running this code on Jenkins and its get "bad substitution"
in regular shell it works.
example:
param1="hello"
param2="world"
PARAMS="param1 param2"
for p in $PARAMS;do
echo ${!p}" "
done
what the best way to make it work in Jenkins too.
You must use with $ sign before the name of the variable:
PARAMS="$param1 $param2"
for p in $PARAMS;do
echo ${p}" "
done
This question already has answers here:
When do we need curly braces around shell variables?
(7 answers)
Closed 3 years ago.
Consider the following code:
name=John
echo ${name}
It prints "John", just as expected. Now consider this code:
name=John
echo $name
Again, this code prints "John" just as expected. Both codes work fine.
But I wonder is there any difference between the two, e.g. compatibility?
In your case, there is no difference.
In this case, there is:
name=John
echo ${name}Doe
echo $nameDoe
Read more: here
This question already has answers here:
Get just the filename from a path in a Bash script [duplicate]
(6 answers)
Closed 4 years ago.
Let's say I have a string which represents the full path of a file:
full_path='./aa/bb/cc/tt.txt'.
How can I extract only the file name tt.txt?
Please don't tell me to use echo $full_path | cut -d'/' -f 5.
Because the file may be located in a deeper or shallower folder.
The number, 5, cannot be applied in all cases.
if you are comfortable with python then, you can use the following piece of code.
full_path = "path to your file name"
filename = full_path.split('/')[-1]
print(filename)
Use the parameter expansion functionality.
full_path='./aa/bb/cc/tt.txt'
echo ${full_path%/*}
That will give you the output
./aa/bb/cc
And will work any number of directory levels deep, as it will give you everything up to the final "/".
Edit: Parameter expansion is very useful, so here's a quick link for you that gives a good overview of what is possible: http://wiki.bash-hackers.org/syntax/pe
You can use this construct
echo "$full_path" | sed 's/\/.*\///'
This question already has answers here:
How to echo "$x_$y" in Bash script?
(4 answers)
When do we need curly braces around shell variables?
(7 answers)
Closed 5 years ago.
I am new at this and I'll simplify my problem. I doing the following script:
echo "Insert number of elements:"
read elements
echo "Insert md number:"
read sim
echo "uni_$elements_md$sim.tpr" >> doc.bash
But when I run the doc.bash file it only shows inside:
uni_4.tpr
Please help me, how must I do my echo so that if I put elements as 14 and sim as 4 (just to put an example), it displays:
uni_14_md4.tpr
Thanks.
This question already has an answer here:
Bash missing $(HOME) variable
(1 answer)
Closed 5 years ago.
i want to know if there is a way to do something like this
VAR="-o sampleoutput"
./mycommand.sh $(VAR)
Thank you
Edit: This question is different. When i tried to run my command withuot parenthesis too but it did not work. Here is my code
ADDITIONAL_ARGUMENTS="-J-javaagent:/opt/newrelic/newrelic.jar &"
./bin -Dconf=./configfile $ADDITIONAL_ARGUMENTS
This is my result
Bad root server path: /path/to/my/project/&
Remove your () around VAR.
VAR="-o sampleoutput"; ./mycommand.sh $VAR