I have installed lessc via npm, Node.js Package Manager, and when I run lessc from terminal using

lessc /var/www/less/style.less /var/www/css/style.css

it works perfectly.
However, when I put this exact same command in a bash script, less.sh, it returns the error

lessc : command not found.

Also, I need to run this command from a bash script, because incron, a program which I am using to re-compile my less script each time they are modified, is unable to run the command mentioned above, which I believe may be caused by weird methods for handling white-space in the command.

  • The non-working script is run in the same terminal where lessc works, or in some other ways (cron, a launcher, Alt-F2, other)? – enzotib Sep 26 '11 at 16:12
  • There's a backtick at the end of your command. Is this typo only here or is it also in your less.sh? – elmicha Sep 26 '11 at 17:33
  • yes the backtick was a typo. @enzotib does it matter where the script is being run from, and would it change anything that could cause the error mentioned above? – slang Sep 26 '11 at 18:41
  • Yes, it matters. In different situation you can have different PATHs. – enzotib Sep 26 '11 at 19:05
  • Thanks, after researching the $PATH variable I found that lessc was in "/opt/lessc/bin/lessc", which needed to be added to $PATH. – slang Sep 27 '11 at 0:02

Where is the "lessc" executable? Do:

type -p lessc

and take note of the directory, and figure out where that directory is added to your PATH. I think that bash and incron do not source your setup files (.bashrc, etc) the same way. Reading the Bash man page, the INVOCATION section describes how bash finds its startup files. A quick grep through the incron source shows that it doesn't mention .bashrc or .bash_profile.

You could change the "lessc" command in your script to:


that you found via

type -p lessc
  • Or add the "/actual/path/to/lessc/" to $PATH, by using the command "PATH=$PATH:/actual/path/to/lessc/" in the bash file. And thanks for posting that as a answer (not a comment). – slang Sep 27 '11 at 19:01
npm install -g less

That installs Less.js globally. Maybe you tried this already but it's not in the documentation on http://lesscss.org/; I had to ask around in #node.js on FreeNode.

  • I execute your command in my ubuntu terminal but I got npm ERR! Refusing to delete: /usr/bin/lessc not in /usr/lib/node_modules/less File exists: /usr/bin/lessc Move it away, and try again. npm ERR! System Linux 3.2.0-90-generic-pae npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "less" npm ERR! cwd /home/best npm ERR! node -v v0.10.40 npm ERR! npm -v 1.4.28 npm ERR! path /usr/bin/lessc npm ERR! code EEXIST npm ERR! not ok code 0 – DaSaDiYa ChaiTAnYa Sep 30 '15 at 18:53

in lubuntu:

$ type -p lessc
$ lessc
El programa «lessc» no está instalado. Puede instalarlo escribiendo:
sudo apt-get install node-less
$ sudo apt-get install node-less

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.