0

I am trying to set the name of a file to a variable with a shell script. I've searched online and found this post, but it is not helping me achieve what I'd like to do which is the following:

JSFILE=ls build/static/js/ | head -1
CSSFILE=ls build/static/css/ | head -1

With, ls ${path} | head -1 I am able to print out the file I want to set a variable to but I keep seeing the following error/output when I try to set the name of the file I want to a variable:

deploy.sh: line 1: build/static/js/: is a directory

Does anyone know how to print out the name of a file to set it to variable in bash?

robskrob
  • 1,986
  • 3
  • 19
  • 36
  • Tip: If you run [ShellCheck](http://www.shellcheck.net/) on your script, it will suggest "[SC2209](https://github.com/koalaman/shellcheck/wiki/SC2209): Use var=$(command) to assign output (or quote to assign string)." – that other guy Jun 18 '17 at 18:23

1 Answers1

0

Did you mean the name of the script which executes your commands? use $0. i.e.

MYVAR=$0
Serge
  • 8,185
  • 2
  • 14
  • 22