Skip to main content
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"). ...
cas's user avatar
  • 84.7k
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 # ...
RedGrittyBrick's user avatar
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 [ &...
Stéphane Chazelas's user avatar
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/...
Stéphane Chazelas's user avatar
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 ...
terdon's user avatar
  • 253k
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 %...
Gilles Quénot's user avatar
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 ...
markp-fuso's user avatar
  • 1,710
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 > ...
canupseq's user avatar
  • 1,994
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 ...
cas's user avatar
  • 84.7k
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 ...
Raffa's user avatar
  • 544
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 ...
waltinator's user avatar
  • 6,892

Only top scored, non community-wiki answers of a minimum length are eligible