Justin
Justin

Reputation: 95

How to use cut command to shorten a file name, and use it inside a bash script?

I would like to use the text of a variable, fileroot, as an input for another command. However, fileroot is based upon the name of another file in the same directory.

So far, I have

for file in *on.nii; do 
    fileroot="cut -c 1-78 ${file}"
done

I am getting an unrecognised option for the -c command. Any ideas on how to limit the {file} to only 78 characters?

Upvotes: 1

Views: 6326

Answers (1)

Rubens
Rubens

Reputation: 14768

Simply address the string, instead of using cut:

for file in *on.nii; do 
    fileroot="${file:0:78}"
done

Upvotes: 4

Related Questions