Free Online Bash Terminal Problem.

59 views
Skip to first unread message

Arthur Dent

unread,
Sep 2, 2021, 2:36:04 AM9/2/21
to rextester
I am getting problems with the following script when using
Either the variable assignment from the expression for result1
is not working, or the echo statement for result1 isn't working.
Can someone either fix rexster, if that is the problem, or tell
me what to do so that the 3rd output is the word 'jump"?

: '
var1="The quick brown fox jumps over the lazy dog.";

var2="jumps";

echo "----";

echo $var1 | grep -b -o $var2 | cut -d: -f1;

#echo $var1 | grep -b -o $var2 | cut -d: -f1;

result1=$var1 | grep -b -o $var2 | cut -d: -f1;

echo "----";

#20
echo $result1;

echo "----";

result2=${var1:result1:4};

#jump
echo $result2;

echo "----";
'

Nachszon Izdebski

unread,
Sep 9, 2021, 8:28:36 AM9/9/21
to rextester
Hello,

1) During the tests, I suggest put the instruction at the beginning of the script:
set -x

2) Instruction
result1=$var1 | grep -b -o $var2 | cut -d: -f1
is not correctly
$result1 will return only value of $var1

3) correctly:
result1=$(echo $var1 | grep -b -o $var2 | cut -d: -f1)
now  $result1 will return 20

End the 3rd output will the word 'jump"
Reply all
Reply to author
Forward
0 new messages