1

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

2
  • foreach is not a shell command and has never been. Maybe you remember programming in php
    – pLumo
    Apr 23, 2020 at 13:39
  • Welcome! What is the context in which you want to use it? And where did you use it before? Apr 23, 2020 at 13:42

1 Answer 1

4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .