mtryingtocode
mtryingtocode

Reputation: 969

Storing number of lines to a variable in UNIX bin/sh

I have a portion in my script which gets the number of files based on the filelist.txt. I'm using this command to store the number to a variable.

filecount=$(wc -l ${script_path}/$filelist.txt | cut -d " " -f 1)

It works ok in my CentOS VM Image, but when it is executed in a UNIX environment it shows this error:

/myscript.sh: syntax error at line 50: `filecount=$' unexpected
./myscript.sh: [[: not found

The filelist contains this which actually just contains a listing of expected files to be processed.

File1
File2
File3

Appreciate any thoughts on this? Does cut not applicable to unix? What alternative methods can I use to get the desired result?

Thanks!

Upvotes: 0

Views: 26

Answers (1)

Romain de Joux
Romain de Joux

Reputation: 61

I can't test on an UNIX sh but I think you just have to replace $() with ``

filecount=`wc -l ${script_path}/$filelist.txt | cut -d " " -f 1`

Regards

Upvotes: 1

Related Questions