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=$(...).
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)
How to assign the output of a Bash command to a variable? [duplicate]
(5 answers)
How do i store the output of a bash command in a variable? [duplicate]
(2 answers)
Closed 3 years ago.
I'm trying to get the number of lines that was printed from the ps command, and save to a variable.
COUNT_PS= ps -C $NAME | wc -l)
the line above prints me 2, but COUNT_PS unfortunately still equals 0 (at the start of the script I've assigned COUNT_PS as 0).
It actually prints the value - but doesn't save it to COUNT_PS.
What am I doing wrong?
This question already has answers here:
How do I set a variable to the output of a command in Bash?
(15 answers)
Bash script store command output into variable
(2 answers)
Save output in variable? [duplicate]
(2 answers)
Store output of sed into a variable [duplicate]
(4 answers)
Assigning the output of a command to a variable [duplicate]
(3 answers)
Closed 4 years ago.
suppose in a file if I have " Route : 8888" , I want to get the string after the pattern "Route :"
I have used sed command, but it is printing 8888 but I want to store it into a variable and use for further processing
So store sed's output in a variable:
ROUTE_VALUE=$(sed ... <file.txt)
Where '...' is your sed command.
$ cat rt.sh
ROUTE=`sed -n 's/.*Route = \(.*\),.*/\1/p' data.txt`
echo $ROUTE
$ bash rt.sh
8888
$ source rt.sh
8888
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
This question already has answers here:
Extract substring in Bash
(26 answers)
Closed 6 years ago.
How to retrieve the first 10 characters of a variable with Bash?
FOO="qwertzuiopasdfghjklyxcvbnm"
I need to get qwertzuiop.
If the variable is: FOO="qwertzuiopasdfghjklyxcvbnm"
then
echo ${FOO:0:10}
will give the first 10 characters.
Use the head command.
echo $FOO | head -c 10
=> qwertzuiop