Skip to main content
8 votes
Accepted

Bash extglob with ignored pattern

In an extglob, !(.min) matches anything that isn't exactly .min (as long it doesn't contain a /), and that includes the empty string!!! So, when you test foo/bar/baz/test.min.js against the extglob ...
Fravadona's user avatar
  • 945
4 votes
Accepted

Understanding bash ‘<’ and ‘>’ with parentheses

Two important things: In your examples echo runs always before cat. Each redirection > file_test creates an independent open file description. Your first example is simple: echo writes to ...
Kamil Maciorowski's user avatar
3 votes

Error parsing memory value in bash script: expected integer expression

On a Ubuntu 24.04.1 LTS system with 32GiB of memory running the free command from the script produces the following result: $ free -mh | awk '/^Mem:/{print $4}' 25Gi Notice that the use of the h (or -...
Chester Gillon's user avatar
3 votes

Details with bash's syntax checking and breaking over several lines

You would want to think of this a bit in terms of "what the program does when it scans what I sent it by pressing enter". In some cases, it starts a new "thing" (like the c in cat: ...
Marcus Müller's user avatar
3 votes

Is there a built-in way to copy a file from current directory to previous directory?

Use the builtin OLDPWD variable. cd /path/to/first/location cd /path/to/second/location cp "some file" "$OLDPWD"
glenn jackman's user avatar
2 votes
Accepted

Return multi-line ssh output to separate variables?

One method could be to assign the values to an array such as in bash: IFS=$'\n' blarge=($( ssh… )) printf "> %s <\n" "${blarge[@]}" But the problem with this is that the ...
Chris Davies's user avatar
2 votes
Accepted

Ctrl-x Ctrl-e bash how to edit previous multiline command

You need to combine your commands into a Compound Command. For example in your editor, use a grouping construct { echo foo echo bar } And then you'll see something like { echo foo; echo bar; } in ...
glenn jackman's user avatar
2 votes
Accepted

rsync - exclude all directories and files except a few

You need to be careful with the difference between a source directory ending with / or not. The example answer you refer to has an ending slash. If you do the same it should work: $ rsync -avn --...
meuh's user avatar
  • 53.1k
2 votes

Should launching background jobs cause a race condition?

You'd have to trace that to see for sure what order everything ends up happening (e.g. with strace on Linux), but note that there's no ordering between how the background processes run and the rest of ...
ilkkachu's user avatar
  • 144k
2 votes

Error parsing memory value in bash script: expected integer expression

As the answer from "Chester Gillon" states, you need to use -m without h. You can also use $7 for the output because free is not the available memory. #!/bin/bash THRESHOLD=500 FREE_MEM=$(...
Z0OM's user avatar
  • 4,491
2 votes
Accepted

Details with bash's syntax checking and breaking over several lines

Here: ( (ls) | cat ) # and ( (ls) | cat ) the subshells are just a distraction. Consider the simpler case: ls | cat # and ls | cat The first is a pipeline with ls on the left-hand side, and cat ...
ilkkachu's user avatar
  • 144k
1 vote

Start Script with SSH Session Name and Date Time

As mentioned in the comments there are multiple ways to accomplish the logging of an SSH session. Here's a few avenues to explore: Logging into ssh with: `ssh user@host "script -T -B session-...
Charles D Pantoga's user avatar
1 vote

Displaying the sed command before its execution in a Bash script

Not a complete answer, but note that this... /bin/bash -c "$*" ...will not do what you want. Let's simplify your RCH function to: RCH() { /bin/bash -c "$*" } Consider the ...
larsks's user avatar
  • 37.5k
1 vote

Details with bash's syntax checking and breaking over several lines

All good answers and comments above, but I'm surprized no one mentioned the "continuation character". I agree that the ( ) sub-shells, are a distraction, you can "fix" your broken ...
shellter's user avatar
  • 679
1 vote

How exactly are results being passed among processes via the pipes?

Pipes are just a special sort of file descriptor which are created in pairs: one for the reading side, one for the writing side. The OS makes anything written to the write side available to be read on ...
ilkkachu's user avatar
  • 144k
1 vote

Speeding up curl in bash scripts

The solution here is probably not in speeding up curl; this would sound like something you might want to do in the background, not in a blocking manner. Anyways, curl is not the speed-limiting factor ...
Marcus Müller's user avatar
1 vote

How to count the no of occurrences of a particular string in a latest log file to read last 5 min data in linux

This will probably do what you want, using any awk and a version of date that lets you subtract a time interval, e.g. GNU date: $ cat tst.sh #!/usr/bin/env bash awk -v err=502 -v thresh="$(date -...
Ed Morton's user avatar
  • 33.9k
1 vote

How to count the no of occurrences of a particular string in a latest log file to read last 5 min data in linux

This: perl -MTime::Piece -snle ' BEGIN{ my $t = localtime; our $now = $t->epoch; our $monthsRe = join "|", $t->mon_list; our $count = 0; } m!...
Gilles Quénot's user avatar
1 vote
Accepted

How to sum all disk size in Linux?

It seems like you can detect the multipathed disks by comparing the NAMEs in the lines of TYPE mpath (for eg. 360060e80225273005041527300000007 appears four times). So, the only fields you need from ...
Fravadona's user avatar
  • 945
1 vote

How to sum all disk size in Linux?

man lsblk lsblk -o size --nodeps --bytes --noheadings will give you a single column of numbers, in bytes, with --nodeps giving you those numbers only for sda sdb without the partitions or other ...
ron's user avatar
  • 7,762
1 vote

How do I use a multi-character delimiter for array expansion in bash?

If the arguments (as in the original example) have no internal spaces, then convert them to a single string, space-separated since space is 1st character of the default IFS value replace every space ...
Vainstein K's user avatar

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