I'm not sure why that error is coming.
Bash Script:
while read line do
grep "^$line$" sort-test1.txt >>matches.txt
done < sort-test2.txt
Error:
syntax error at line 5: `done' unexpected
Please tell me why this error is occuring.
If you wanted to obtain the lines in common in 2 text files. You can execute a simple shell command:
grep -F -x -f sort-test1.txt sort-test2.txt > matches.txt
I think that it is what you need.
Related
This file is written in bash. When I run it I get this error:
./q: line 7: syntax error near unexpected token `done'
./q: line 7: `done '**strong text**
The code is:
nohup echo ELMAYET > /dev/null 2> /dev/null &&
if curl -m5 -s --insecure "$1/test/final" | grep "phpshell" > /dev/null;
then
echo "$1/test/final.php" | tee -a final.txt;
fi &
done
Assuming there's nothing else of significance in your script, you simply need to delete the done.
done is a shell keyword. It's used only to mark the end of a while, for, or until loop. If it doesn't mark the end of a loop, it's a syntax error.
Out of curiosity, what did you think the done was for, and why did you add it to the script? If you assumed you need a done to mark the end of the script, that's your mistake. The end of a script doesn't need to be marked in any special way; it's just the end of the file.
whenever I try
irb(main):008:0> `while read FILENAME; do echo "Hi";done < <(cat /tmp/a)`
I get the following error:
sh: 1: Syntax error: redirection unexpected
Is there anyway to bypass this issue, but still use back ticks for the shell exec from ruby?
I have very small shell script.When I am running it run flow. it is giving "syntax error near unexpected token `(". Very basic question but sorry not able to figure out.
foreach i ( `cat list407`)
mkdir cells/${i}
cp /<path>/$i/${i}.gds cells/${i}/${i}.gds
end
Error:
flow: line 1: syntax error near unexpected token `('
flow: line 1: `foreach i ( `cat list407`)'
You've used csh syntax for execution using bash which is causing the error.
Either use csh to execute your script, or using bash say:
while read -r i; do
mkdir "cells/${i}"
cp "/<path>/${i}/${i}.gds" "cells/${i}/${i}.gds"
done < list407
for i in $(cat list407); do
mkdir cells/${i};
cp /<path>/$i/${i}.gds cells/${i}/${i}.gds;
done
I am receiving an error with my Cron job. The error I keep getting is:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
Here is my code:
mysqldump -u database_user -p']T%zw51' database > /home/site/public_html/Secure/Cron/Database_Backup/database_backup.sql
You may need to escape the % with a \.
% is a special character to the crontab, which gets translated to a newline, so your code was probably becoming
-p']T
zw51'
Try:
-p']T\%zw51'
If there some difference between the bash of Mac OS and other linuxs'?
I wrote a simple bash script named "test.sh" like this:
#!/bin/bash
MYVAR=abc
if [ $MYVAR = abc ]; then
echo "ok"
fi
When I run it in terminal, some error occurs:
./test.sh: line 3: syntax error near unexpected token `then'
./test.sh: line 3: `if[ $MYVAR = abc ]; then'
then I delete the character ";" before "then" and run the script again, some infos occurs:
./test.sh: line 3: if[ abc = abc ]: command not found
ok
./test.sh: line 5: syntax error near unexpected token `fi'
./test.sh: line 5: `fi'
Could someone tell me what's wrong with my script?
Consider putting spaces into your file the way you put it in your example (if [).
[ is a command (same as test). It must be separated by spaces on both sides.