I am new to shell scripting and solaris operating systems. I want to write a script that monitors disk usage. Following some tutorials online I got started with it. As a first step I tried to assign the output of a command to a variable and echo it.


CURRENT=$(df -h /ccviews1|sed -n '2p'|awk '{print $5 }'|sed 's/%//g')

When I run the script, it is giving below error

./diskMonitor.sh: syntax error at line 3: `CURRENT=$' unexpected

Please help me with this issue. Also, I would like to if writing shell scripts in Ubuntu and writing in Solaris are same. If there is any difference, how should I proceed?

  • What version of Solaris are you using? Earlier versions of Solaris have /bin/sh as the Bourne Shell.
    – user14755
    Commented Aug 18, 2016 at 7:19
  • Try #!/bin/bash instead.
    – schaiba
    Commented Aug 18, 2016 at 7:28
  • /bin/sh is not Bash. GNU/Linux conflates the two. Commented Aug 21, 2016 at 0:39

1 Answer 1


If you are using Solaris 10 and older, you need to adjust your script one of these ways:

Portable to the legacy Bourne shell:

CURRENT=`df -h /ccviews1|sed -n '2p'|awk '{print $5 }'|sed 's/%//g'`

Use a POSIX shell

PATH=$(getconf PATH):$PATH
CURRENT=$(df -h /ccviews1|sed -n '2p'|awk '{print $5 }'|sed 's/%//g')

Use Solaris mainstream shell (bash will work too here)


CURRENT=$(df -h /ccviews1|sed -n '2p'|nawk '{print $5 }'|sed 's/%//g')

You must log in to answer this question.

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