Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to run this code in bash but I can't. Bash doesn't run it! it's like it's waiting for me to continue and it doesn't think that my command is done! But I'm already done! I know that the problem is with read <<<. so how can I fix it?
Here is my code:
for f in `ls *| head -100`; do a=$(file "$f" | grep -Po ", \K\d+x\d+"`);
> IFS="x";
> read x y <<< "$a";
> done;
>
>
You have a superfluous backtick:
for f in `ls *| head -100`; do a=$(file "$f" | grep -Po ", \K\d+x\d+"`);
# Here ---^
IFS="x";
read x y <<< "$a";
done;
ShellCheck helpfully points this out. Voting to close as a simple typographical error.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
In my mac terminal I am trying to store the output of a command into a variable like this
$ animals=$(cat animals.txt | head -n $plusOne | tail -n $numberofanimals | sort -u | sed -E "s/[*#/#2]//g; s/D/d/g ; s/G/g/g ; s/E/e/g ; s/H/h/g ; s/O/o/g ; s/C/c/g ; s/[!]//gā)
>
but it does not work. When I press Enter I get a > prompt on the next line. Any idea why?
You've got a smart quote ā at the end of the line instead of a regular double quote ".
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I a trying to read a file line by line and add the value of each line after making some changes to a variable.
Currently I am using this-
COM="Something i"
while IFS= read -r line || [ -n "$line" ];
do
LINE="Line${line/=/,}End"
COM="$COM$LINE"
done < Vars
COM="$COM done"
echo "Vars" | piping_into_some_other_application
The content of file vars-
VAL=something
VAL2=somethingelse
VAL3=some
VAL4=vals
I finally expect COM to be-
Something iLineVAL,somethingEndLineVAL2,somethingelseEndLineVAL3,someEndLineVAL4,valsEnd done
But I get-
LineVAL4,valsEnd done
With Your solution $LINE and $COM gets overwritten with every iteration instead of appending.
You can do this with gawk if that is available too look this:
awk '{gsub("=",",") ; V = V "Line" $1 "End" } END { print "Something i" V "done"}' INPUTFILE | some_other_application
(And You can do it with sed, perl etc.)
With bash it can be done like
COM=""
while IFS= read -r line ; do
COM="${COM}Line${line/=/,}end"
done < INPUTFILE
echo "Something i${COM} done" | some_other_program
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
In bash shell how do we assign extracted substring into variable without 'bad substitution' errors, please?
For example with the codes below:
fruit="apple"
echo $fruit | cut -c1-3
variable=$"{echo $fruit | cut -c1-3}"
The second line returns 'app' but the third line can't really work without bad substitution error.
Replace
variable=$"{echo $fruit | cut -c1-3}"
with
variable=$(echo $fruit | cut -c1-3)
do this instead
$ fruit=apple; var="${fruit:0:3}"; echo "$var"
app
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
Why can't I run two commands within a single line bash loop?
$ for i in {1..100} do printf %s "$(date)" ; mysql -uroot -e "SHOW SLAVE STATUS\G" | grep "Seconds_Behind_Master" ; sleep 10 ; done
-bash: syntax error near unexpected token `mysql'
But this simple version works:
for i in {1..3}; do echo $i ; ls ; done
You need a ; after your brace expansion. You have it in the simple example, but not in the "broken" one:
for i in {1..100}; do printf %s "$(date)" ; mysql -uroot -e "SHOW SLAVE STATUS\G" | grep "Seconds_Behind_Master" ; sleep 10 ; done
^ this one
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am just wondering (and I'm stumped), why the if statement isn't working as it should. Have I missed something simple?
#!/bin/bash
echo -e "\nFinding the thing things on the thing, presently.\n"
DEVICE=$1
IPADDRESS=$(/sbin/ifconfig $DEVICE | grep -A 0 'inet addr:' | cut -c21-29)
for i in {1..255}
do
HOST=$(ping -c 1 $IPADDRESS.$i | grep -A 0 'from' | cut -c15-25)
if ["$HOST" != ""]
then
echo "$HOST is ALIVE!!!"
fi
done
You need to add spaces between:
if [ "$HOST" != "" ]