I recently installed Ubuntu 18.04.4. I'd previously used the foreach command on older Ubuntu versions without a problem, but now I'm getting "command not found". Not sure if this is due to a newer version of ubuntu, or if something went wrong during installation. Any advice would be greatly appreciated! Ben
1 Answer
foreach
is a construct in the C shell and its variants (csh
or Tenex tcsh
for example).
Ex.
#!/bin/csh
foreach i (`seq 1 3`)
echo "$i"
end
The default interactive shell used in Ubuntu is bash
, where the equivalent syntax would be
#!/bin/bash
for i in $(seq 1 3); do
echo "$i"
done
If you have older scripts that rely on csh
, you can install the BSD csh
package and/or Tenex tcsh
package from the Ubuntu repository. However please see Top Ten Reasons not to use the C shell.
foreach
is not a shell command and has never been. Maybe you remember programming inphp