This question already has answers here:
Why should eval be avoided in Bash, and what should I use instead?
(3 answers)
Variables as commands in Bash scripts
(5 answers)
Closed 5 years ago.
Command="tr ' ' '\n' < /location/to/file.xml | sed -e '/\/Name/, $d' | grep Apple | wc -l"
New_command=`$Command`
The error I am getting:
tr: extra operand \'\\n\'' Trytr --help' for more information.
What is wrong with what I am doing? Trying to assign a string variable to 'New_Command' so I can execute it and get the output.
Related
This question already has answers here:
How do I iterate over a range of numbers defined by variables in Bash?
(20 answers)
Variables in bash seq replacement ({1..10}) [duplicate]
(7 answers)
Closed 5 months ago.
I have asked way too many dumb questions here, but here we go.
Code:
#!/bin/bash
for i in {0..$#}; do
ascii ${!i} | grep "\`" | tail -c 3 | head -c 1;
done
echo
(This is to translate long binary input, like from those horror games that have binary at the end)
Error message:
./asciit: line 4: {0..2}: invalid variable name
Command run:
./asciit 01101000 01101001
Why?
This question already has answers here:
How do I set a variable to the output of a command in Bash?
(15 answers)
Closed 4 years ago.
$USERNAME =$($INI$LNAME | tr '[:upper:]' '[:lower:]')
This is not working. How can i make it work?
Your assignment should be USERNAME=$(...).
This question already has answers here:
How do I use variables in single quoted strings?
(8 answers)
Closed 4 years ago.
The below expression
var=$(git log --since='$start_date' --until='$end_date' --author='$commit_author' | grep -i 'merge request\|pull request' | wc -l)
echo $var
prints var as zero
but if I echo the above expression
git log --since='2018-04-1' --until='2018-06-30' --author='so.sila#xes.com' | grep -i 'merge request\|pull request' | wc -l
and copy it and execute via terminal works
why is that var not storing the value and returns zero
The reason is that '$start_date', '$end_date' etc do not expand to their values as they are in single quotes. Try changing it to double quotes and you may have some luck.
This question already has answers here:
Floating-point arithmetic in UNIX shell script
(4 answers)
floating-point operations with bash
(3 answers)
"Invalid Arithmetic Operator" when doing floating-point math in bash
(5 answers)
Closed 5 years ago.
I am trying to multiply decimals and echo them
Here is what I have so far ...
#!/bin/bash
gbspace=1
limitUsers=2
limitInstances=2
echo $(($gbspace*0.5)) GB Webspace
echo limitUsers:$(($limitUsers*5))
echo limitUsers:$(($limitUsers*5)), limitInstances:$(($limitInstances)) \| Hi
and this is what I get ...
root#home /home/work # bash run
run: line 7: 1*0.5: syntax error: invalid arithmetic operator (error token is ".5")
limitUsers:10
limitUsers:10, limitInstances:2 | Hi
Use bc which is pre-installed on most systems, with the -l flag to enable floating-point arithmetic:
echo $(echo "$gbspace*0.5" | bc -l) "GB Webspace"
Note that you have to be careful with the quoting, and you have to pipe the expression you want to compute to bc with the echo command.
This question already has answers here:
extracting a string between two quotes in bash
(3 answers)
Closed 6 years ago.
I have a string that looks like:
result='SNMP OK - "-63.1" |' # output should be -63.1
result='SNMP OK - "63.1" |' # output should be 63.1
I need the to output everything between the quotes -- which should always be numeric.
var='SNMP OK - "-63.1"';
newvar=$(echo "$var" | sed -r 's/.*"(.*)".*/\1/')
echo "$newvar"
-63.1