I have the following code working in Debian system's:

for File in "${Files[@]}"; do
    if test "`find $FolderDownload/$File -cmin -190`" ; then
        echo "File is new then 3 hours"

        # Set concatenation

        # Get out ot next step
        echo "There's no change in the $File in past 6 hours"

How can I use it on FreeBSD system on the default csh?

Actually I'm trying:

foreach File ($Files)
    if (test find $FolderDownload/$File -cmin -190) then
        echo "File is new then 3 hours"

        # Set concatenation

        # Get out ot next step
        echo "There's no change in the $File in past 6 hours"

But its returning the error:

if: Expression Syntax.

The content of variables is somenthing like:

Files = {"File1.txt","File2.txt","File3.txt","File4.txt"}

FolderDownload = "/var/scripts/"

FileConcat = 0

  • does putting a backquote before the find and another after the -190 help in your csh script in the same way as they exist in your debian script? Does your FreeBSD system not have /bin/sh?
    – icarus
    Commented Oct 21, 2019 at 21:36
  • Yes have the /bin/sh, wierd thing is seems ignore it, the script start like debian: #!/bin/sh but does not works, I have changed a lot of code from the script to make compatible. The backquote does not also, I am testing now with if ( { test 'find $FolderDownload/$File -type f -cmin -190' } ) ... But this always is returning the path of file now got the hint from: [link]grymoire.com/Unix/Csh.html#toc-uh-26
    – Wisdom
    Commented Oct 21, 2019 at 21:50
  • Using: if ( { find $FolderDownload/$File -type f -cmin -190 } ) then remove the syntax error, but, empty values on if become true.
    – Wisdom
    Commented Oct 21, 2019 at 21:57
  • Now using the previous way, the problem is with the find command, seems does not work as desired... if I do: if ( { find $FolderDownload/$File -type f -cmin -190} == "") command always return false and I know there are some true values. If I do same command on shell I can see the true files.
    – Wisdom
    Commented Oct 21, 2019 at 22:03
  • I know how to install Bash :p, and the problems of use it, like on single mode / recovery mode... (Yes i know too about the toor user also...) Because this, I am avoiding to change the default shell and asking to do it on csh, for me does not make sense change shell for run one script and get a lot of other's problems since all scripts on FreeBSD is crafted for they default shell.
    – Wisdom
    Commented Oct 21, 2019 at 22:48

1 Answer 1


You state in your comments that you know:

  1. How to install bash.
  2. Not to change the default shell away for root.
  3. Bash does not install into /bin and is hence not available first hand in single user mode.
  4. Of the toor user.

All the above is correct and good for you!

A small misconception which is not important. The toor user was created for this purpose. It has uid 0 (as root does) so you can set any shell you like for toor.

A larger misconception is that most FreeBSD scripts are written in (t)csh. They are not! System script are written in sh. Just have a look at /bin/freebsd-version or /usr/bin/zdiff

Bash is not part of the FreeBSD Operating System. But the system does not become impure if you install and use it. You do not even have to change the user shell. But if you do - just keep your hands of root.

There are however larger issues at hand.

Do not write scripts in csh!!!

Even though the default root shell is (t)csh you should never ever write csh scripts on any system. That is pretty common consensus and if you need the full story please read CSH PROGRAMMING CONSIDERED HARMFUL


Whenever you write a script you should start the first line with the "shebang" (see more in Bash Shebang). This tells the system which interpreter to use when executing the script. You can with no problem execute a bash (or perl/zsh/etc) script from csh.

For the best portability use:

#!/usr/bin/env bash

This will look through $PATH to find your location of bash. To me this is the best solution.

Others advocate that you should never do that but specify the exact location. This then adds a requirement to the target system. Either you update shebang shen moving a script - or you ensure the target system has a link to bash in /bin.

Use sh for broad portability

If you want even better portability then use the sh shell for scripting. It has less features than bash but you can be sure it is available on all POSIX(-like) systems.

Shell scripting is hard!

Writing a proper shell script can be really hard. The first and best tool to help you is Shellcheck. You can install it locally as well.

Make it a habit to check your scripts - this will save you from many headaches.

  • After read the article on link CSH PROGRAMMING CONSIDERED HARMFUL, i give a try on your alternative and seems wonderfull!!! Same script with some extra validations (check OS, case for each OS using specific paths, etc...) and now I have same script working on FreeBSD / Debian / Ubuntu, have not tested on other enviroments. I will follow this way, tyvm.
    – Wisdom
    Commented Oct 22, 2019 at 20:46

You must log in to answer this question.

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