10
votes
Accepted
How do I ensure a bash script argument is a specific value?
The main problem with your script is a boolean logic error. In your elif clause you are testing for ("not cli OR not gui") when you should be testing for ("not cli AND not gui").
...
8
votes
How do I ensure a bash script argument is a specific value?
I suspect you can accomplish what you want in bash and in a way that is much easier for others to read and understand.
$ cat t.bash
#!/usr/bin/bash
croak() { # dying words
readonly RED=4 # ...
7
votes
How do I ensure a bash script argument is a specific value?
No need to use the Korn-style [[ ... ]] let alone Bash's =~ in there, you could use the standard case construct which would make your code more legible.
RED=$'\e[31m' RESET=$'\e[m'
die() {
while [ &...
7
votes
How can I use sed to chain append lines from a text file, add it as a suffix to the text on the same lines numbers on another file, and so on?
how can I use this kind of strategy: while IFS= read -r line; do echo "$line"
Don't. That's not how shells are meant to be used.
For most text processing, I'd use perl which has made sed/...
6
votes
Choice of field separator affects sort's ordering
Using a field separator with sort only makes sense if you sort on specific fields. If not, then the field separator is irrelevant. And that's why you get different sorting. So you're not seeing the ...
5
votes
How can I use sed to chain append lines from a text file, add it as a suffix to the text on the same lines numbers on another file, and so on?
What I would do, using a template engine, here Perl's tpage from Template::Toolkit module, the clean and maintainable way:
Template:
cat rss.tmpl
<outline type="rss" title="[% title %...
3
votes
How can I use sed to chain append lines from a text file, add it as a suffix to the text on the same lines numbers on another file, and so on?
For the 1st data set ...
Assumptions/understandings:
the title, text and htmlUrl attributes are derived from the last 2 dot-delimited strings in the domain (eg, for feed.site4.info we're interested ...
2
votes
How can I use sed to chain append lines from a text file, add it as a suffix to the text on the same lines numbers on another file, and so on?
Not sure about sed. But you can do it using awk and paste and some temporary files:
$ awk -F/ '{print $3}' links.txt | tee long | awk -F. '{print $1}' >short
$ paste links.txt long short > ...
2
votes
Accepted
White spacing is causing variable to not contain all text in result
The first parentheses pair, i.e. the ( immediately before the $(sudo...) and its matching ) at the end, are causing $result to be populated as an array.
To confirm this, try typing declare -p result
I ...
2
votes
Accepted
Process sed capture group with a bash function before replacement: "sh: 1: <bash function>: not found"
sed runs shell commands in a sub-shell of the default system shell i.e. whatever /bin/sh links to (Usually a POSIX shell like dash) that shell doesn't support exporting user defined functions (which ...
1
vote
Process sed capture group with a bash function before replacement: "sh: 1: <bash function>: not found"
Without the shebang selecting /bin/bash, your system selects /bin/sh, an older, simpler shell, that doesn't understand the bashisms you use.
Before your file's first line,
#!/bin/bash
will tell the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bash × 28049shell-script × 6994
shell × 4214
linux × 2881
scripting × 1579
awk × 1021
command-line × 990
sed × 975
terminal × 820
grep × 730
text-processing × 725
ssh × 716
find × 683
variable × 648
ubuntu × 597
io-redirection × 595
zsh × 584
pipe × 575
environment-variables × 545
files × 542
alias × 516
quoting × 508
command-history × 463
wildcards × 461
regular-expression × 446