Artificial intelligent assistant

Substrings in shell script Am trying to get a substring from a string but am getting the error: `${curr_rec:3:4}: bad substitution` #!/bin/ksh get_file_totals() { if [ -e "$file_name" ] then IFS='' while read line do curr_rec=$line echo ${curr_rec:3:4} done < "$file_name" else echo "error" fi } file_name="$1" get_file_totals

It would be more efficient to rewrite this, thereby avoiding the issue in the first place:


#!/bin/ksh

get_file_totals()
{

if [ -e "$file_name" ]
then
cut -c4-7 "$file_name"
else
echo "error" # consider stderr by appending >&2
fi
}

file_name="$1"
get_file_totals

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d72b138de6de1478ae5cb8c29ebb2dcc