Shell: test: argument expected

The following shell script might work just fine on many of the available shell interpreters but the same would fail with the ‘test: argument expected’ error if you try to execute it under sh on Solaris platform.

#!/usr/bin/sh

touch /tmp/i_exist
if [ -e /tmp/i_exist ]; then
  echo "file exists!"
fi

So, what we are trying in the above script is to check if the given file exists using shell’s [condition].
As per Solaris test(1):


-e file — True if file exists. (Not available in sh.)

A simple solution to this issue is to use ‘-f’ instead. It checks for the existence of regular files and supposed to work on most of existing shell interpreters.

3 thoughts on “Shell: test: argument expected”

  1. that worked..thanks!!
    i have two linux servers, on one -e works , but on other it doesnt
    server_A: Linux server_A 2.6.32-131.0.15.el6.x86_64 #1 SMP Tue May 10 15:42:40 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

    server_B:Linux server_B 2.6.32-131.0.15.el6.x86_64 #1 SMP Tue May 10 15:42:40 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

Leave a Reply

Your email address will not be published. Required fields are marked *