databasher
Re:Free Introduction to Bash Scripting eBook
on Wednesday July 17, 2024 @07:07PM (#40991160)
With lines.txt:
printf '(%s)\n' "one two" "three four five"
echo "How you doin'?"
Running: while read -r line; do
eval command=($line)
command+=("arg with spaces" "other arg")
"${command[@]}"
done < lines.txt
Yields (one two)
(three four five)
(arg with spaces)
(other arg)
How you doin'? arg with spaces other arg
Re:Free Introduction to Bash Scripting eBook
on Wednesday July 17, 2024 @06:12PM (#40990851)
Bash handles spaces just fine.
# store the command in an array
X=(echo "A B")
# execute the command
"${X[@]}"
Yields: A B
Re:UPS to Cut 12,000 Jobs and Mandate Return to Offices Five Days a Week
on Tuesday January 30, 2024 @03:55PM (#39195702)
Meanwhile, UPS's web site has mostly gone down. Their home page now reads "Sorry! We Can’t Find That Page. Looks like the page you’re trying to find may have been moved or deleted."
Re:Argbash – Bash Argument Parsing Code Generator
on Tuesday March 21, 2023 @12:10PM (#35248230)
The video in the linked page says that getopts only supports short options.
Re:Argbash – Bash Argument Parsing Code Generator
on Monday March 20, 2023 @05:43PM (#35239203)
If you refer to my example above, you'll find that Bash's native "getopts" handles long options just fine. It accepts short option `-`, with an argument. This handles --long-options and --long-options=with-arguments.
Feel free to use your own formatting preferences.
Re:Argbash – Bash Argument Parsing Code Generator
on Monday March 20, 2023 @03:46PM (#35237527)
Handling command-line arguments in Bash is easy. Bash's `getopts` handles short and long arguments gnu-style without any problem, out of the box, without any need for libraries or complicated packages.
This pattern handles lots of styles of options: short and long options (-h, --help), `--` for separating options from positional args, with GNU-style long options (--output-file=$filename).
while getopts :o:h-: option
do case $option in
h ) print_help;;
o ) output_file=$OPTARG;;
- ) case $OPTARG in
help ) print_help;;
output-file=* ) output_file=${OPTARG##*=};;
* ) echo "bad option $OPTARG" >&2; exit 1;;
esac;;
'?' ) echo "unknown option: $OPTARG" >&2; exit 1;;
: ) echo "option missing argument: $OPTARG" >&2; exit 1;;
* ) echo "bad state in getopts" >&2; exit 1;;
esac
done
shift $((OPTIND-1))
(( $# > 0 )) && printf 'remaining arg: %s\n' "$@"
Re:Google open sources solar atmospheric water generator
on Thursday March 17, 2022 @03:44PM (#30715129)
It turns out they are very similar to binary loadlifters in most respects.
Re:Bash functions are better than I thought
on Sunday October 31, 2021 @11:40PM (#29062791)
Bash `getopts` handles short and long arguments gnu-style without any problem. The following code handles args like "-h", "-i $input-file", "-i$input-file", "--in=$input-file", and "--help":
while getopts :i:h-: option
do case $option in
# accept -i $input-file, -i$input-file
i ) input_file=$OPTARG;;
h ) print_help;;
- ) case $OPTARG in
help ) print_help;;
help=* ) echo "Option has unexpected argument: ${OPTARG%%=*}" >&2; exit 1;;
in=* ) input_file=${OPTARG##*=};;
in ) echo "Option missing argument: $OPTARG" >&2; exit 1;;
* ) echo "Bad option $OPTARG" >&2; exit 1;;
esac;;
'?' ) echo "Unknown option $OPTARG" >&2; exit 1;;
: ) echo "Option missing argument: $OPTARG" >&2; exit 1;;
* ) echo "Bad state in getopts" >&2; exit 1;;
esac
done
shift $((OPTIND-1))
Re:Bash code generator for command-line arguments
on Friday October 02, 2020 @11:43AM (#24663774)
Thanks!
Re:Bash code generator for command-line arguments
on Friday October 02, 2020 @11:27AM (#24663594)
Like @bxparks, I have a template for my bash scripts command-line parsing, but I like to stick to GNU-style options and I find that Bash's getopts command handles all these cases without trouble:
command -ffilename -f filename --file=filename -- -f is not an option
My template is at https://gist.github.com/webb/ff380b0eee96dafe1c20c2a136d85ef....
Re:Hubble finds that Betelgeuse's dimming is likely due to ejection of...
on Friday August 14, 2020 @01:09PM (#24160459)
It would not be difficult. Nuclear reactors could provide power almost indefinitely. Greenhouses could maintain plant life. Animals could be bred and slaughtered. A quick survey would have to be made of all the suitable mine sites in the country, but I shouldn't be surprised if several hundred thousand of our people could be accommodated. Every nation would undoubtedly follow suit.
Re:Create diagrams with code using Graphviz
on Wednesday June 10, 2020 @08:52AM (#23476485)
I use GraphViz to produce a visual, browsable version of the NIEM data model. GraphViz can output images and HTML maps, which allows easy building of clickable web pages with hover notes.
See the diagram at https://niem.github.io/model/4.2/nc/ItemType/ . Hover over a term to see its definition. Click on a term to navigate to its diagram.
Re:Copy Bulk Files in Linux
on Wednesday May 06, 2020 @10:56AM (#23091660)
My go-to would be tar:
`$ tar -C $source-dir -c . | tar -C $dest-dir -x`
Re:Bash Argument Parsing and Quoting (2016)
on Thursday March 05, 2020 @02:31PM (#22497177)
Why not use bash's printf %q?
string=$(printf ' %q' "${array[@]}")
Re:Markdeep – plain text documents with diagrams, equations, and Markd...
on Monday February 17, 2020 @03:09PM (#22350292)
Pandoc calls these "Line blocks": https://pandoc.org/MANUAL.html#line-blocks
Re:Tcl: Everything Is a String
on Monday October 28, 2019 @11:58AM (#21378090)
TCL had an amazing architecture for someone who was working in C. In C, you'd (1) create an instance of a TCL interpreter, (2) register your C functions with the TCL interpreter, and then (3) load scripts into the TCL interpreter. You'd do all your fast stuff in your C code, and just use the TCL for stitching together the high-level logic.