If you want to use cut
this way, you need to use redirection <<<
(a here string) like:
var=$(cut -c-5 <<< "$line")
Note the use of var=$(command)
expression instead of id= cut -c-5 $line
. This is the way to save the command into a variable.
Also, use /bin/bash
instead of /bin/sh
to have it working.
Full code that is working to me:
#!/bin/bash
filename='sample.txt'
while read -r line
do
id=$(cut -c-5 <<< "$line")
echo $id
#code for passing id to other script file as parameter
done < "$filename"