Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

3 votes
1 answers
196 views
Why SIGTSTP (^Z/Ctrl-Z/suspend) doesn't work when process blocked redirecting write into a FIFO/pipe not open for reading yet? And what to do then?
Sometimes, a command is stalled attempting to write to a FIFO/pipe that no other process is currently reading from, but typing Ctrl - Z to put the process to the background by sending it the SIGTSTP signal (i.e. the *suspend* non-printing control character `^Z`) does work. Example: $ mkfifo p $ ll p...
Sometimes, a command is stalled attempting to write to a FIFO/pipe that no other process is currently reading from, but typing Ctrl-Z to put the process to the background by sending it the SIGTSTP signal (i.e. the *suspend* non-printing control character ^Z) does work. Example: $ mkfifo p $ ll p prw-rw-r-- 1 me me 0 Jul 30 16:27 p| $ echo "Go!" >p # Here & has been forgotten after the >p redirection (stalled) [Ctrl-Z] ^Z # Pressing Ctrl-Z just prints "^Z" on the terminal, nothing else happens [Ctrl-D] # Attempting to send the EOF character (nothing) # Doesn't print "^D" and does nothing and this is the behavior even though SIGTSTP (or susp) is reported to be attached to ^Z: $ stty -a speed 38400 baud; rows 24; columns 91; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany -imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc How comes that in this case the terminal does not catch and transmit to the process the SIGTSTP signal generated by the Ctrl-Z? Is it because redirecting with > to a FIFO/pipe puts the terminal in raw mode (cf. The TTY demystified )? But if so, why does "^Z" get printed on the screen, and why Ctrl-D (EOF) doesn't print anything and yet doesn't have any effect either? Incidentally, is there an alternative way to send the stalled process to the background in such cases (instead of just terminate the process with Ctrl-C (i.e. ^C / SIGINT)?
The Quark (402 rep)
Aug 5, 2025, 08:47 AM • Last activity: Aug 5, 2025, 12:02 PM
10 votes
4 answers
1073 views
Using `find` to find a file in PATH
I would like to be able to search all my `$PATH` for files matching a given pattern. For example, if my PATH is `/usr/local/bin:/usr/bin:/bin` and there's a `/usr/local/bin/gcc-4` and a `/usr/bin/gcc-12`, I would like to be able to search for `gcc-*` to find them both. The trivial approach of course...
I would like to be able to search all my $PATH for files matching a given pattern. For example, if my PATH is /usr/local/bin:/usr/bin:/bin and there's a /usr/local/bin/gcc-4 and a /usr/bin/gcc-12, I would like to be able to search for gcc-* to find them both. The trivial approach of course does not work:
find ${PATH} -name "gcc-*"
this naive approach does work:
find $(echo "${PATH}" | sed -e 's|:| |g') -name "gcc-*"
but of course this is breaks if PATH holds any weird characters like space and the like. So how can I achieve this in a safe way? My shell is sh.
umläute (6704 rep)
Jul 30, 2025, 12:35 PM • Last activity: Aug 3, 2025, 05:36 PM
1 votes
1 answers
41 views
On start of an interactive shell, is there something that gets called between ~/.zshenv and ~/.zshrc? My PATH is getting changed between them
According to the docs, the order of .zsh files is ``` .zshenv .zprofile .zshrc .zlogin ``` As suggested by the docs, I put my $PATH in .zshenv. I echo it there and I can see it. But something is changing $PATH by the time .zshrc is called. I put an `echo $PATH` at the top of it and I see it has chan...
According to the docs, the order of .zsh files is
.zshenv
.zprofile
.zshrc
.zlogin
As suggested by the docs, I put my $PATH in .zshenv. I echo it there and I can see it. But something is changing $PATH by the time .zshrc is called. I put an echo $PATH at the top of it and I see it has changed. So what could be changing it? Mac OS btw
Paul C (1005 rep)
Aug 1, 2025, 09:42 PM • Last activity: Aug 2, 2025, 07:58 AM
3 votes
1 answers
2906 views
nmap won't recognize a hostname on my local area network
Scanning the machine on the LAN with my laptop, I got this: gabriele @ osiris { ~ } [ Tue Oct 07 ] [ 08:49 PM] nmap -sP 192.168.1.236 Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-07 20:50 CEST Nmap scan report for ---.homenet.telecomitalia.it (192.168.1.236) Host is up (0.0044s latency). Nmap d...
Scanning the machine on the LAN with my laptop, I got this: gabriele @ osiris { ~ } [ Tue Oct 07 ] [ 08:49 PM] nmap -sP 192.168.1.236 Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-07 20:50 CEST Nmap scan report for ---.homenet.telecomitalia.it (192.168.1.236) Host is up (0.0044s latency). Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds nmap won't recognize the nostname, putting—in place of "mercury" and I assume is not a problem of nmap because it doesn't even access in this way: root@mercury when I changed the hostname I follow these steps sudo nano /etc/hostname and I wrote a single line with "mercury", then: sudo nano /etc/hosts with this configuration: 127.0.0.1 localhost 127.0.1.1 mercury localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters and finally: sudo /etc/init.d/hostname.sh start am I doing something wrong?
Gabriele Salvatori (131 rep)
Oct 7, 2014, 07:06 PM • Last activity: Aug 2, 2025, 05:10 AM
23 votes
2 answers
9079 views
List of shells that support `local` keyword for defining local variables
I know that Bash and Zsh support `local` variables, but there are systems only have POSIX-compatible shells. And `local` is undefined in POSIX shells. So I want to ask which shells support `local` keyword for defining local variables? **Edit**: About shells I mean the default `/bin/sh` shell.
I know that Bash and Zsh support local variables, but there are systems only have POSIX-compatible shells. And local is undefined in POSIX shells. So I want to ask which shells support local keyword for defining local variables? **Edit**: About shells I mean the default /bin/sh shell.
mja (1525 rep)
Jan 10, 2019, 02:13 PM • Last activity: Aug 1, 2025, 01:19 PM
3 votes
2 answers
107 views
Localising variables in /bin/sh functions
POSIX defines [shell functions](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_05) as: ``` fname ( ) compound-command [io-redirect ...] ``` The [compound-command](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04) is further d...
POSIX defines [shell functions](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_05) as:
fname ( ) compound-command [io-redirect ...]
The [compound-command](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04) is further defined as either:
( compound-list )
{ compound-list ; }
In particular POSIX notes for the first form that "_variable assignments and built-in commands that affect the environment shall not remain in effect after the list finishes._" I've noticed that the idiomatic structure with bash code seems to be to use a braced compound list with the local keyword: f1() { local arg1=$1 arg2=$2 p q # arg1, arg2, p, q are all local vars shift 2 … } In general, assuming the function doesn't modify global variables, we can simplify this to use the bracketed form that implicitly localises all its variables: f2() ( arg1=$1 arg2=$2 # all variables are implicitly local shift 2 … ) Aside from using local as an explicit declaration of local variables, is there any general reason to prefer the braced f1() { …; } construct, which seems to be more commonly used than f2() ( … )?
Chris Davies (126543 rep)
Jul 30, 2025, 04:18 PM • Last activity: Aug 1, 2025, 01:09 PM
38 votes
11 answers
40063 views
Check if script is started by cron, rather than invoked manually
Is there any variable that cron sets when it runs a program ? If the script is run by cron, I would like to skip some parts; otherwise invoke those parts. How can I know if the Bash script is started by cron ?
Is there any variable that cron sets when it runs a program ? If the script is run by cron, I would like to skip some parts; otherwise invoke those parts. How can I know if the Bash script is started by cron ?
daisy (55777 rep)
Aug 31, 2012, 09:07 AM • Last activity: Aug 1, 2025, 12:17 PM
3 votes
2 answers
8271 views
How to export proxy in Redhat Linux 7 using the current login credentials?
I need to export proxy on RHEL 7 with the current logged user credentials. I am able to achieve this by adding manually in **.bashrc or .bash_profile.**: export http_proxy=http://username:password@proxy.example.com:6080 export https_proxy=http://username:password@proxy.example.com:6080 The above met...
I need to export proxy on RHEL 7 with the current logged user credentials. I am able to achieve this by adding manually in **.bashrc or .bash_profile.**: export http_proxy=http://username:password@proxy.example.com:6080 export https_proxy=http://username:password@proxy.example.com:6080 The above method works fine. But I don't want this method, since we are hard-coding the username and password and also it's not secure. Is it possible to use the existing **/etc/shadow** file as password for exporting the proxy?
M S (291 rep)
Apr 22, 2018, 10:23 AM • Last activity: Jul 30, 2025, 09:07 AM
136 votes
14 answers
276203 views
Generate random numbers in specific range
After googling a bit I couldn't find a simple way to use a shell command to generate a random decimal integer number included in a specific range, that is between a minimum and a maximum. I read about `/dev/random`, `/dev/urandom` and `$RANDOM`, but none of these can do what I need. Is there another...
After googling a bit I couldn't find a simple way to use a shell command to generate a random decimal integer number included in a specific range, that is between a minimum and a maximum. I read about /dev/random, /dev/urandom and $RANDOM, but none of these can do what I need. Is there another useful command, or a way to use the previous data?
BowPark (5155 rep)
Jul 4, 2014, 12:18 PM • Last activity: Jul 29, 2025, 08:39 AM
51 votes
6 answers
55436 views
/dev/tcp listen instead of nc listen
With a netcat listener like: nc -l / > ~/.bashrc My question is: Is there a way to mimic the capabilities of `nc -l ` in my first line with /dev/tcp instead of `nc`? The machines I'm working on are extremely hardened lab/sandbox environment RHEL (no ssh, no nc, no LDAP, no yum, I can't install new s...
With a netcat listener like: nc -l / > ~/.bashrc My question is: Is there a way to mimic the capabilities of nc -l in my first line with /dev/tcp instead of nc? The machines I'm working on are extremely hardened lab/sandbox environment RHEL (no ssh, no nc, no LDAP, no yum, I can't install new software, and they are not connected to the internet)
h3rrmiller (13506 rep)
Oct 4, 2012, 06:26 PM • Last activity: Jul 27, 2025, 06:42 PM
5 votes
4 answers
6647 views
How to use fish on remote servers that have it installed without changing login shell?
I regularly `ssh` on several different servers, some of which don't have `fish` installed, but many do. I'd like to get `fish` as shell if available (changing midway is always tedious, and you lose the history of what you already typed), but changing the default shell is not a good idea, as: - there...
I regularly ssh on several different servers, some of which don't have fish installed, but many do. I'd like to get fish as shell if available (changing midway is always tedious, and you lose the history of what you already typed), but changing the default shell is not a good idea, as: - there are many different machines that I would need to change; - on many other I'm logged in through LDAP, and changing my shell as stored on LDAP would break on machines where fish is not available; - in general, as fish is not POSIX-sh compatible putting it as default shell may break commands executed by scripts through ssh; - finally, there are a few machines where the user is shared with other people (or, where I have to login another user), so changing the default shell is not a good idea. So, ideally I'd like to have a command like ssh that automagically starts fish if available, or just leave whatever default shell is provided otherwise.
Matteo Italia (534 rep)
Oct 17, 2018, 07:57 PM • Last activity: Jul 27, 2025, 10:33 AM
0 votes
1 answers
28 views
Storing the iterations of the Receiver (or node) number and RSSI value into an CSV file
I'm quite new to Linux. Recently, I've been able to create a bash script that allows me to obtain the RSSI of the receivers (or node) with a running iteration. How can I store these results in an CSV file with a format such as: Node RSSI ... [...,...] ... [...,...] Here is what the output looks like...
I'm quite new to Linux. Recently, I've been able to create a bash script that allows me to obtain the RSSI of the receivers (or node) with a running iteration. How can I store these results in an CSV file with a format such as: Node RSSI ... [...,...] ... [...,...] Here is what the output looks like when running the file: bash test.sh -l 170,171 -k 2 === Iteration 1 === Node RSSI ------ ---------- 170 -43 dBm 171 -43 dBm === Iteration 2 === Node RSSI ------ ---------- 170 -43 dBm 171 -44 dBm
Trinh Dat (1 rep)
Jul 25, 2025, 08:57 PM • Last activity: Jul 25, 2025, 09:33 PM
2 votes
4 answers
136 views
Grep (BRE) on surrounding delimiters w/o consuming the delimiter? Counting delimiter-separated strings between filename and extension
I have a dataset of images labeled/classified by characteristics, where an image can have more than one label. I want to count how many of each identifier I have. A toy dataset is created below, with different colors being the labels. ```bash bballdave025@MY-MACHINE /home/bballdave025/toy $ touch el...
I have a dataset of images labeled/classified by characteristics, where an image can have more than one label. I want to count how many of each identifier I have. A toy dataset is created below, with different colors being the labels.
bballdave025@MY-MACHINE /home/bballdave025/toy
$ touch elephant_grey.jpg && touch zebra_white_black.jpg && touch rubik-s_cube_-_1977-first-prod_by_ErnoRubik-_red_orange_yellow_white_blue_green.jpg && touch Radio_Hotel.Washington_Heights.NYC-USA_green_yellow_blue_red_orange_reddish-purple_teal_grey-brown.jpg && touch Big_Bird__yellow_orange_red.jpg
Let's make it more easily visible. The files in the initially labeled dataset are shown below. (The | awk -F'/' '{print $NF}' is just meant to take off the ./ or path/to/where/the/jpegs/are/ that would otherwise be before the filename.)
$ find . -type f | awk -F'/' '{print $NF}'
Big_Bird__yellow_orange_red.jpg
elephant_grey.jpg
Radio_Hotel.Washington_Heights.NYC-USA_green_yellow_blue_red_orange_reddish-purple_teal_grey-brown.jpg
rubik-s_cube_-_1977-first-prod_by_ErnoRubik-_red_orange_yellow_white_blue_green.jpg
zebra_white_black.jpg
Those are the filenames for labeled versions of the images. The corresponding originals are below:
$ find ../toy_orig_bak/ -type f | awk -F'/' '{print $NF}'
Big_Bird_.jpg
elephant.jpg
Radio_Hotel.Washington_Heights.NYC-USA.jpg
rubik-s_cube_-_1977-first-prod_by_ErnoRubik-.jpg
zebra.jpg
This is to show that the color labels are inserted between the filename and the dot extension. They are separated from each other and from the original filename by a (delimiting) _ character. (There are rules for the label names and for the filenames1.) The only allowed color strings at this initial point are any of {black, white, grey, red, orange, yellow, green, blue, reddish-purple, teal, grey-brown}. I further want to show that other labels may be added, as long as they're part of my controlled vocabulary, something which can be changed only by me. Imagine a file named rainbox.jpg gets put in with the original filenames ( touch ../toy_orig_bak/rainbow.jpg, for those of you following along for reproducibility ). I decide that I want to add indigo and violet to my controlled vocabulary list, so I can create the labeled filename,
$ touch rainbow_red_orange_yellow_green_blue_indigo_violet.jpg
Desired Output Again, I want a count of each of the labels. For the dataset I've set up (including that last labeled picture of a rainbow), the correct output would be
1 black
      3 blue
      3 green
      1 grey
      1 grey-brown
      1 indigo
      4 orange
      4 red
      1 reddish-purple
      1 teal
      1 violet
      2 white
      4 yellow
(The counts were performed somewhat manually, due to my grep confusion.) Attempts and a note on the details of the solution I want Research below My first thought (although I did worry about delimiter consumption) was to look at the surrounding delimiters: '_' before and '_' or '.' after. Here's first my grep attempt
find . -type f -iname "*.jpg" | \
 \
    grep -o "[_]\(black\|white\|grey\|red\|orange\|yellow\|green\|blue\|"\
"reddish-purple\|teal\|grey-brown\|indigo\|violet\)[_.]" | \
 \
        tr -d [_.] | sort | uniq -c
and its output
3 blue
      1 green
      1 grey
      1 orange
      3 red
      1 teal
      1 violet
      1 white
      3 yellow
Which is not the same as before. Here's the comparison.
Before              |   Now
-----------------------|---------------------
      1 black          |
      3 blue           |      3 blue
      3 green          |      1 green
      1 grey           |      1 grey
      1 grey-brown     |
      1 indigo         |
      4 orange         |      1 orange
      4 red            |      3 red
      1 reddish-purple |
      1 teal           |      1 teal
      1 violet         |      1 violet
      2 white          |      1 white
      4 yellow         |      3 yellow
                       |
I know this is happening because the regex engine consumes the second delimiter2. Here is the crux of my main question: (I do want to solve my count problem, and I'll talk about some solutions I've researched and considered myself, but) the detail I want to know is about truly regular expressions and consuming the delimiter. I want to get a count of each identifier string, and I'm wondering if I can do it with approach and (POSIX) Basic Regular Expressions – BRENote 2 and [reddit thread](https://www.reddit.com/r/askscience/comments/5rttyo/do_extended_regular_expressions_still_denote_the/) ([archived as a gist](https://gist.github.com/bballdave025/b2f7a190907146151696eed394079a64)) , specifically with grep . Any of sed, awk, IFS with read, etc. are welcome, too. I'm sure someone has a way solve this problem with Perl (dermis and feline can be divorced by manifold methods), and I'd be glad to get that one, too. Basically, I am absolutely okay with other solutions to the task of getting a count of each identifier string. However, if it's true that there's no way of stepping back the engine with a Basic Regular Expression engine (that's truly regular), I want to know. I've thought of zero-width matches, lookaheads, and look-behinds, but I don't know how these play out in POSIX Basic Regular Expressions or in mathematically/grammatically regular language parsers. One thing I realize I wasn't taking into account The point of the rules (see note \[2\]) was to allow the regex to take advantage of the fact that we should be able to assure ourselves that we're only getting the part of the classified filename with labels, as we only allow one of a finite set of strings preceded by an underscore and followed by either an underscore or a dot, with the dot only happening before the file extension. (I guess we can't be absolutely certain, as the original, pre-labeled filename could have one of the labels immediately preceding the dot - something like a_sunburn_that_is_bright_red.jpg, but that's something for which I check and correct by adding a specific non-label string before the dot and extension.) My regex, imagining that it could get past the delimiter being consumed, would still allow the following example problems
the_new_red_car_-_1989_red_black_silver.jpg
- would return {red, red , silver } as is, - {red, red, black , silver } if working without consuming the 2nd '_', - whereas {red, black , silver } is desired
parrot_at_blue_gold_banquet_-_a_black_tie_affair_yellow_red_green.jpg
- would return {blue, black, yellow, green} as is, - {blue, gold, black, yellow, green} if not consuming the 2nd '_', - whereas {yellow, red, green} is desired Extra points for answers and discussions that take that into account. ; ) Research and ideas There are a few discussions on different StackExchange sites, like [this one](https://web.archive.org/web/20230925145242/https://stackoverflow.com/questions/63821591/how-to-split-a-string-by-underscore-and-extract-an-element-as-a-variable-in-bash) , [that one](https://web.archive.org/web/20250602171231/https://stackoverflow.com/questions/49784912/regex-of-underscore-delimited-string) , [another one](https://web.archive.org/web/20250602171046/https://unix.stackexchange.com/questions/267677/add-quotes-and-new-delimiter-around-space-delimited-words) , but I think the [Unix & Linux discussion here](https://unix.stackexchange.com/a/334551/291375) ([archived](https://web.archive.org/web/20230324152449/https://unix.stackexchange.com/questions/334549/how-do-i-extract-multiple-strings-which-are-comma-delimited-from-a-log-file)) is the best one. I think that one of the approaches in this answer from @terdon ♦ or in the answer with hashes – from @Sobrique – might be useful. I keep thinking that some version of ^.*\([_][]\)\+[.]jpg$ might be key to the situation, but I haven't been able to put together that solution today. If you know how it can help, you're welcome to give an answer using it; I'm going to wait for a fresh brain tomorrow morning. Edit: @ilkkachu successfully used this idea. Why am I doing this? I'm training a CNN to recognize different occurrences (not colors) in pictures of old and often handwritten books. I want to make sure the classes are balanced as I want. Also, I'll compare this with another method that doesn't look at the delimiter to make sure I don't have any problems like a '_yllow' (instead of '_yellow'), or a '_whiteorange' _instead of '_white_orange'). Most of the labels are put on through a Java program I've put together, but I've given a little leeway for people to change the filenames themselves in case of multiple labels for one file. Having given that permission, I have the responsibility of verifying legal labeled filenames. Notes \[1\] The rules for the identifying/classifying labels are: The identifiers can be any of a finite set of strings which can contain only characters in [A-Za-z0-9-] but not underscores.
The bare filenames (without dot and extension) can consist of any ASCII characters except: 1) non-printable/control characters; 2) spaces or tabs ; OR 3) any of [!"#$%&/)(\]\[}{*?] See the next paragraph for the real 3). (Note that this means the bare filenames CAN have an underscore, '_', or even several of them.)
Edit: I had my no-no list of characters as is now crossed (struck) out above when @ilkkachu gave the accepted answer. One option of that answer makes excellent use of the '@' which was then not in the excluded character group, but which I actually don't allow in my filenames. There are other omissions in the original character group. As I actually want it, the above paragraph should be amended with the following. 3) any of '[] ~@#$%^&|/)(}{[*?>\ Edit: Now this compiles as a BRE. (This was the simplest and most-readable BRE I could come up with.) that beautifully crazy character group means that any of { [, ], , ~, @, #, $, %, ^, &, |, \, /, ), (, }, {, [, *, ?, >, `} is not allowed – and neither is any tab (\t, ...), nor any non-printing/control characters. Some of these are already standard on the no-no list for filenames on different OSs, but I give _my_ complete set (when I'm in charge of creating the filenames). \[2\] Here is what I mean by the delimiter being consumed. I'll do my best to illustrate an example with our (Basic) Reg(ular)Ex(pression),
"[_]\(black\|white\|grey\|red\|orange\|yellow\|green\|blue\|"\
"reddish-purple\|teal\|grey-brown\|indigo\|violet\)[_.]"
Here goes. This missing of some of the color strings is happening because the regex engine consumes the second delimiter. For example, using O to denote part of a miss (non-match) and X to denote part of a hit (match), with YYYYY denoting a complete match for the whole regex pattern, we get the following behavior.
Engine goes along looking for '_'

engine is here
       |
       v
rainbow_red_orange_yellow_green_blue_indigo_violet.jpg
OOOOOOO

Matches 
      [_]
          with '_'
engine is at
        |
        v
rainbow_red_orange_yellow_green_blue_indigo_violet.jpg
OOOOOOOX

Matches
 \(...\|red\|...\)
                  with 'red'    
  engine is at
           |
           v
rainbow_red_orange_yellow_green_blue_indigo_violet.jpg
OOOOOOOXXXX
Matches
          [_.]
               with '_'
   engine is at
            |
            v
rainbow_red_orange_yellow_green_blue_indigo_violet.jpg
OOOOOOOXXXXX

We have a whole match! 

rainbow_red_orange_yellow_green_blue_indigo_violet.jpg
OOOOOOOYYYYY

Given the  -o  flag, the engine outputs

'_red_'

The  'tr -d [_.]' takes off the surrounding underscores, 
and our output line becomes 

'red'
The problem now is that the engine cannot go back to find the '_' before 'orange', or at least it can't do so using any process I know about from my admittedly imperfect knowledge of Basic Regular Expressions. As far as a REGULAR expression engine, using a REGULAR grammar and a REGULAR language parser knows, the whole universe in which it's searching now consists of
orange_yellow_green_blue_indigo_violet.jpg
(I don't know if this statement is correct from a mathematical/formal-language point of view, and I'd be interested to know.) And the process continues as from the first, beginning with Engine goes along looking for '_'
orange_yellow_green_blue_indigo_violet.jpg
OOOOOOXXXXXXXX

Match!

orange_yellow_green_blue_indigo_violet.jpg
OOOOOOYYYYYYYY

Engine spits out  '_yellow_'  which is 'tr -d [_.]'-ed

Engine cannot go back, so its search universe is now

green_blue_indigo_violet.jpg

and we continue with

green_blue_indigo_violet.jpg
OOOOOXXXXXX

Match!

green_blue_indigo_violet.jpg
OOOOOYYYYYYOOOOOOYYYYYYYY

That last match being on the '.' from [_.]
More formally, I want to know if it can be done with a real regular expression, i.e. one which can define a regular language and whose language is a context-free language, cf. Wikipedia's Regex article (archived). I think this is the same as a POSIX regular expression, but I'm not sure.
Refs. [A] (archived), [B] (archived), [C] (archived), Dang it, I know there's a missing ending parenthesis up there in the text, somewhere, because I noticed it and went up to fix it. When I got up into the text, I couldn't remember the context of the parenthesis, so it's still there, just mocking me. I found it, and I bolded it! I'll probably take the bold formatting and this note down, soon, but I'm sharing my happiness right now.
bballdave025 (418 rep)
Jun 3, 2025, 04:56 AM • Last activity: Jul 25, 2025, 03:50 AM
0 votes
1 answers
722 views
grep behaviour is different when run using bash -c '...'
I met an interesting issue while working with this code from Stack Overflow: [tripleee's answer on "How to check if a file contains only zeros in a Linux shell?"][1] Why does the same bash code produce different result depending on interactive shell or subshell? Make all-zeros file with name `your_f...
I met an interesting issue while working with this code from Stack Overflow: tripleee's answer on "How to check if a file contains only zeros in a Linux shell?" Why does the same bash code produce different result depending on interactive shell or subshell? Make all-zeros file with name your_file.
$ truncate -s 1K your_file
Interactive shell example
$ tr -d '\0' 
The same code but using subshell
$ bash -c 'tr -d '\0' 
And also interesting fact. I changed original example by adding -a option ("equivalent to --binary-files=text") because without this option interactive shell works but subshell:
$ bash -c 'tr -d '\0' 
P.S. I use bash 5.2.37(1)-release from Ubuntu 25.04
Андрей Тернити (303 rep)
Jul 21, 2025, 01:34 PM • Last activity: Jul 24, 2025, 04:33 AM
30 votes
7 answers
31500 views
How to cat files together, adding missing newlines at end of some files
I have a bunch of `.text` files, _most_ of which end with the standard nl. A couple don't have any terminator at end. The last physical byte is (generally) an alphameric character. I was using `cat *.text >| /tmp/joined.text`, but then noticed a couple of places in joined.text where the first line o...
I have a bunch of .text files, _most_ of which end with the standard nl. A couple don't have any terminator at end. The last physical byte is (generally) an alphameric character. I was using cat *.text >| /tmp/joined.text, but then noticed a couple of places in joined.text where the first line of a file appeared at the end of the last line of a previous file. Inspecting the previous file, I saw there wasn't a line terminator -- concatenation explained. That raised the question, what's the easiest way to concatenate, sticking in the missing newline? What about these options? 1. A solution that might effectively add a blank line to some input files. For me, that's not a problem as the processing of joined.text can handle it. 2. A solution that adds the cr/fl only to files that do not already end that way.
HiTechHiTouch (991 rep)
Feb 16, 2017, 07:17 PM • Last activity: Jul 23, 2025, 10:22 AM
12 votes
4 answers
24839 views
How can I preserve an environment variable across su -?
I export `LC_ALL="en_US.UTF-8"` (via `sendEnv` in ssh_config) when using ssh to remote systems. When I `su - user123` this variable is reset by the login shell. Is there a way to preserve this variable (as well as other `LC_xxx` variables) when executing a login shell as another user on the remote s...
I export LC_ALL="en_US.UTF-8" (via sendEnv in ssh_config) when using ssh to remote systems. When I su - user123 this variable is reset by the login shell. Is there a way to preserve this variable (as well as other LC_xxx variables) when executing a login shell as another user on the remote system? I realize I could export the variable by hand after executing the shell, or an entry in ~/.bashrc of the target user, however I'd rather try to preserve the original values as sent by ssh if possible. Thanks. **EDIT**: I do need specific parts of the user's environment initialized which is why su - is used. I would only want to preserve LC_xxx
Server Fault (577 rep)
Jan 30, 2017, 06:03 PM • Last activity: Jul 23, 2025, 06:36 AM
78 votes
8 answers
16931 views
How to restore the value of shell options like `set -x`?
I want to `set -x` at the beginning of my script and "undo" it (go back to the state before I set it) afterward instead of blindly setting `+x`. Is this possible? P.S.: I've already checked [here][1]; that didn't seem to answer my question as far as I could tell. [1]: https://unix.stackexchange.com/...
I want to set -x at the beginning of my script and "undo" it (go back to the state before I set it) afterward instead of blindly setting +x. Is this possible? P.S.: I've already checked here ; that didn't seem to answer my question as far as I could tell.
Roney Michael (883 rep)
Sep 20, 2016, 01:05 AM • Last activity: Jul 22, 2025, 02:48 PM
45 votes
4 answers
21775 views
What happens if you edit a script during execution?
I have a general question, which might be a result of misunderstanding of how processes are handled in Linux. I am going to define a 'script' as a snippet of bash code saved to a text file with execute permissions enabled for the current user. I have a series of scripts that call each other in tande...
I have a general question, which might be a result of misunderstanding of how processes are handled in Linux. I am going to define a 'script' as a snippet of bash code saved to a text file with execute permissions enabled for the current user. I have a series of scripts that call each other in tandem called A, B, and C. Script A carries out a series of statements, then pauses, then executes script B, then pauses, then executes script C. The series of steps is like this: Run Script A: 1. Series of statements 2. Pause 3. Run Script B 4. Pause 5. Run Script C If I run script A until the first pause, then make edits in script B or C, those edits are reflected in the execution of the code when I allow it to resume Is there any way to edit Script A while it is still running? Or is editing impossible once execution begins?
CaffeineConnoisseur (665 rep)
Aug 28, 2013, 03:37 AM • Last activity: Jul 22, 2025, 02:09 PM
0 votes
3 answers
1964 views
sed? - Insert line after a string with special characters to Neutron service
I am attempting to write a bash script that will insert a string after matching on a string in /usr/lib/systemd/system/neutron-server.service I have been able to do this on other files easily as I was just insert variables into neccessary config files, but this one seems to be giving me trouble. I b...
I am attempting to write a bash script that will insert a string after matching on a string in /usr/lib/systemd/system/neutron-server.service I have been able to do this on other files easily as I was just insert variables into neccessary config files, but this one seems to be giving me trouble. I believe the error is that sed is not ignoring the special characters. In my attempt I have tried using sed of single quotes and double quotes (which I understand are for variables, but thought it might change something. Is there a better way of going about this or some special sed flags or syntax I am missing? sed ‘/--config-file /etc/neutron/plugin.ini/a\--config-file /etc/neutron/plugins/ml2/ml2_conf_cisco_apic.ini‘ /usr/lib/systemd/system/neutron-server TL;DR - Insert --config-file /etc/neutron/plugins/ml2/ml2_conf_cisco_apic.ini After --config-file /etc/neutron/plugin.ini Orginial File [Unit] Description=OpenStack Neutron Server After=syslog.target network.target [Service] Type=notify User=neutron ExecStart=/usr/bin/neutron-server --config-file /usr/share/neutron/neutron- dist.conf --config-dir /usr/share/neutron/server --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini --config-dir /etc/neutron/conf.d/common --config-dir /etc/neutron/conf.d/neutron-server - -log-file /var/log/neutron/server.log PrivateTmp=true NotifyAccess=all KillMode=process TimeoutStartSec="infinity" [Install] WantedBy=multi-user.target File after desired change command. [Unit] Description=OpenStack Neutron Server After=syslog.target network.target [Service] Type=notify User=neutron ExecStart=/usr/bin/neutron-server --config-file /usr/share/neutron/neutron- dist.conf --config-dir /usr/share/neutron/server --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini --config- file /etc/neutron/plugins/ml2/ml2_conf_cisco_apic.ini --config-dir /etc/neutron/conf.d/common --config-dir /etc/neutron/conf.d/neutron-server - -log-file /var/log/neutron/server.log PrivateTmp=true NotifyAccess=all KillMode=process TimeoutStartSec="infinity" [Install] WantedBy=multi-user.target
fly2809 (1 rep)
Jun 13, 2017, 08:48 PM • Last activity: Jul 22, 2025, 09:04 AM
2 votes
3 answers
5223 views
How to stop execution of command from prompt in shell?
My prompt contains some info about git repo under current directory. When I do `cd` somewhere, my shell executes some commands (i.e. `git status`). Is there a way to stop execution of such commands via the same terminal? Sending signals from keyboard (e.g. via Ctrl + c ) doesn't work. ### Update #1...
My prompt contains some info about git repo under current directory. When I do cd somewhere, my shell executes some commands (i.e. git status). Is there a way to stop execution of such commands via the same terminal? Sending signals from keyboard (e.g. via Ctrl+c) doesn't work. ### Update #1 I don't want to disable those commands permanently - I just want them to start running and then stop them in runtime.
abyss.7 (189 rep)
Jan 10, 2018, 01:32 PM • Last activity: Jul 22, 2025, 03:02 AM
Showing page 1 of 20 total questions