shell script error expecting do
I suspect line endings.
Try:
hexdump -C yourscript.sh
And look for 0d 0a
sequences. You can strip \r
(0d
) with the tr
command:
cat yourscript.sh | tr -d '\r' >> yournewscript.sh
for loop shell script syntax error: unexpected word (expecting do )
Found a ^M when i opened it in vi editor. It helped me to solve it.
so it was some thing like this when i opened it in vi editor
for file in $PRO
do^M
echo $file
done^M
Later used the dos2unix command by referring to computerhope.com/unix/dos2unix.htm
Syntax error: end of file unexpected (expecting do )
If it should be an infinite loop try
while [ 1 = 1 ]
do
nohup php retrieve4.php 1 > /dev/null 2>&1 &
nohup php retrieve4.php 2 > /dev/null 2>&1 &
done
EDIT
while [ 1 ]
do
echo 'test'
done
This is running perfectly well on my setup. Therefore I'd expect your method of running the script is wrong
You could also try something like this:
while true ; do php my_script.php ; done > /dev/null
Shell script for loop error: Syntax error: word unexpected (expecting do )
It turned out to be extraneous characters after all. I ran the following command and the script started working afterwards. Sorry for the confusion, and thanks for the help everyone!
tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file
error: unexpected end of file (expecting do ) for shell script in Dockerfile
Remove the square brackets []
, and use ;
at the end of lines because docker joins lines when sees your \
's, so the commands get melt.
This is working for me:
RUN cat .env | while read LINE ;\
do \
envName=$(echo "$LINE" | grep -o "^[^\=]*"); \
echo "PassEnv $envName" >> httpd.conf ;\
done
Related Topics
Rm Fails to Delete Files by Wildcard from a Script, But Works from a Shell Prompt
Difference Between Netstat and Ss in Linux
Difference Between Vm.Dirty_Ratio and Vm.Dirty_Background_Ratio
Why Does the Linux Kernel Repository Have Only One Branch
Linux Distribution Binary Compatibility
How to Schedule Tcpdump to Run for a Specific Period of Time
Display Only Files and Folders That Are Symbolic Links in Tcsh or Bash
New to Linux Kernel/Driver Development
How to Diff a Directory for Only Files of a Specific Type
How to Execute a Series of Commands in a Bash Subshell as Another User Using Sudo
How to Copy File from a Vagrant MAChine to Localhost
How to Calculate System Memory Usage from /Proc/Meminfo (Like Htop)
Linux, Why Can't I Write Even Though I Have Group Permissions
What Are My Environment Variables