Linux is a kernel. The script you show is a shell script.
In the Bourne family of shells, all atomic variables are strings. (In Bash / ksh / etc there are also arrays which are collections of strings.)
To strip quotes from both sides of a string, try this sequence of parameter expansions:
value=${value%\"}
value=${value#\"}
Using shell built-ins will be a lot quicker than using an external process, though each of these should be fairly obvious if you had googled at all before asking:
value=$(echo "$value" | tr -d '"') # discards " everywhere
value=$(sed 's/^"\(.*\)"$/\1/' <<<"$value") # Bash specific <<<here string
value=$(awk -v val="$value" 'BEGIN { sub(/^"/, "", val); sub(/"$/, "", val); print val }')
Your loop will read and discard all values in the file, then process whatever was on the last line of the file. I'm guessing you want to process each value inside the loop instead?
while IFS="" read -r line; do
result=${line%\"}
result=${result#\"}
[ $result -gt 0 ] && { echo "Failed" >&2; exit 1; }
done < File.csv
(notice IFS=""
and read -r
, and printing the error message to standard error instead of standard output) but a much better solution is to use Awk for this (the shell's while read -r
is horribly inefficient and usually wrong);
awk '{ sub(/^"/, ""); sub(/"$/, "");
if (0+$0 > 1) { print "Failed" >>"/dev/stderr"; exit 1 } }' File.csv