sh scripting question
bob at proulx.com
Sun Oct 18 20:38:06 UTC 2020
Kurt Hackenberg wrote:
> Bob Proulx wrote:
> > Oh you are tormenting us now. :-) There are some subtle issues here.
> Maybe a shell is the wrong tool.
And yet just the same the shell does handle whitespace and arbitrary
characters in file names easily.
while IFS= read -r line; do
printf "|%s|\n" "$line"
done < file1
It's a shell programming idiom. It accomplishes the task very easily.
For people programming in the shell every day this type of construct
rolls off the fingers like a native language. But it may not be
immediately obvious without a hint that this is what is needed.
Idiom, id-ee-uhm, noun. An expression conforming or appropriate to
the peculiar structural form of a language.
Nothing we have seen yet makes the shell the wrong tool. The shell is
a very powerful command and control language. And so far the original
need was still for using it specifically as a command and control
language. So all good so far! If we move to needing complex data
structures however that is where my decision point is set to move to a
language that supports complex data types.
And I think everyone is in agreement that the filenames that were
chosen were not the file names that any Unix person would choose to
name their files. No disagreement there. I am sure they were chosen
by less enlightened individuals. Given that the files on disk were
chosen for a different purpose then can we handle them easily in the
shell? Yes. So far nothing too difficult! :-)
More information about the freebsd-questions