veganism.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
Veganism Social is a welcoming space on the internet for vegans to connect and engage with the broader decentralized social media community.

Administered by:

Server stats:

202
active users

#shellscripting

1 post1 participant1 post today

Apropos an ongoing project, looking at sed, and realising:

  • It can execute external commands (e)
  • It can read in entire files at a given address within the input stream (r).
  • It can read in specified external files on a line-by-line basis at a specified address within the input stream (R).

I've only been using sed for, oh, 40 years.

gnu.org/software/sed/manual/se

www.gnu.orgsed, a stream editorsed, a stream editor

I think I won't bother anymore with writing (bash) shell scripts that are longer than a few lines. I find the syntax too unintuitive and there are better programming languages like PHP that produce more readable code.

In the last two hours, I translated a bash shell script with ~250 lines to a PHP CLI script. The latter is nearly 400 lines long but definetly more readable and it also has more user-friendly output.

1/2

Interesting #ShellScripting quandary:

I'm uncertain how shells delimit filename variables internally.

I have a shell (bash) function that loops through a set of PDF files, opening them in zathura in a "suckless" tabbed window (so that the PDFs always open within the same window, so I can just hit q to zip through them one-at-a-time.

Here is my variable declaration:

local files=${*-*.[pP][dD][fF]}

But for simplicity, you could just imagine it to be:

files=*

Then I'm doing a

for f in $files; do

I'm wanting to print a status line for each item viewed, so I have an idea how many more there are to go, so I'm using this:

echo "[[$f]] ($count/$tot)"

And of course, there's a ((count++)) at the beginning of the loop.

But how to get the total ($tot)??

echo $files |wc -l will always result in 1, as does echo "$files" |wc -l

What I ended up doing was just creating a

for f in $files; do ((tot++)); done

One-liner loop before the actual loop, just to get a total.

Is there a better way?

Am I missing something really obvious?

Je viens d'arriver à écrire un script shell en une ligne de awk pour un projet Kirby bilingue où je dois formater des gros fichiers .txt exportés depuis un tableau de traduction sous forme de tableau PHP indentés correctement, et ça me rend heureux :

`awk -F$' \t*' '{gsub(/[ \t]+$/,"",$1); print " \""$1 "\" => \"" $2 "\","}' input.txt`

Alors que c’est pas fou hein en soi, mais c’est tellement satisfaisant quand ça marche !

I have ask for this before but got no answers so I try again :-)

If you go to a browser on a computer (Vivaldi in my case but I don't think it matter) and click on the url box, you'll notice the url is automatically selected. You can press ctrl-c and this url will be copied to the clipboard.

However, if I go to a terminal and type 'xclip -out -selection primary' I will either get nothing or whatever was selected before. In any cases, not my url.

If I deselect the url and re-select it again, then it works as expected.

What is special about this "one-click automatic selection" that make it different from another normal selection?