All Questions
Tagged with bash-functions or bash
27,278 questions
2
votes
1
answer
132
views
Detectng missed SIGWINCH in Bash extension, when apparent terminal size has not changed
I maintain an extension for the Bash environment called Basta. Basta provides a scroll-protected status line at the bottom of your ANSI/VT100 terminal.
When Basta sets itself up, the effective number ...
4
votes
3
answers
755
views
How to remove 'newline' from 'here string'
The 'here string' (<<<) is a useful construct, and can be used in lieu of echo in many situations. However, when calculating a hash (as one example) the addition of a newline character ...
0
votes
0
answers
99
views
inserting colored properties into files
when it comes to the echo -e command, of course you can do a lot with it when it comes to printing color text, especially when it comes to making terminal based UIs, but I have one main question, does ...
1
vote
3
answers
165
views
Bash/macOS: Getting a variable by its name, inside of a function [duplicate]
In Bash for macOS, I need to be able to pass a string to a function and return the value of a variable named after that string, as well as the string itself.
Here's what I have so far, which doesn't ...
12
votes
3
answers
2k
views
Why can't sed change /dev/zero's output characters to something else?
This works
head -c 10 /dev/zero | sed 's/\x0/x/g'
and generates xxxxxxxxxx as expected.
Then I tried this:
sed 's/\x0/x/g' /dev/zero | head -c 10
which seems to just hang.
Then I thought, oh, sure, ...
6
votes
2
answers
741
views
How can I extract quoted strings within a variable?
I acknowledge there are superficially similar questions asked here before, but all of those I've seen are simpler than what I'm trying to achieve. Bash-only solutions are preferred.
I have a variable ...
4
votes
1
answer
95
views
What are the rules that determine file permissions of b after I do cp /path/to/a /p/t/b, depending on file permissions of /path/to/a and all dirs?
In Classic Shell Scripting from O'Reilly, Arnold Robbins and Nelson H.F. Beebe write the follwing example:
$ umask
023
$ rm -f foo
$ cp /bin/pwd foo
$ ls -l /bin/pwd foo
-rwxr-xr-x 1 root root ...
2
votes
1
answer
338
views
When trying to unzip file from script, I get Segmentation fault (core dumped)
I'm trying to unzip a file in a bash script, but I get a 'Segmentation fault (core dumped)' error following a repeated output message of 'Unzip agent files.'
Unzip agent files.
Unzip agent files.
...
4
votes
2
answers
187
views
Print out bash color codes in order of color hue
I have found multiple posts regarding color in bash terminals - but I was wondering if there was a way to verbosely print out the color code along with a sample of that color in order of hue.
Right ...
0
votes
0
answers
42
views
Error when indexing a Bash Array to echo or make a command [duplicate]
I have a shell script that I want to run many times. Each time, I want to use a different argument that comes from a CSV file. The file is very simple:
code1-code2-01
code1-code2-02
code1-code2-03
...
0
votes
3
answers
133
views
Is it possible to find the complete command list to be executed in a sub-shell?
I face a situation that features Bash scripts on a Linux installation that asynchronously run system tools with a delay, via a
( sleep 10 ; some_command ) &
construct. The scripts that perform ...
-5
votes
1
answer
56
views
Linux advance permission [closed]
Tasks:
as alpha-user:
Create a new simple BASH script file and set SUID permission.
Check if the SUID bit is set on the file. Run the file as beta-user to verify that it executes with the owner's ...
0
votes
1
answer
118
views
In Bash 5.2+, is there a means to read the command currently being evaluated?
...that is to say, is there a means by which I can read the full command that's being evaluated AS it's happening? Here's a contrived example, but one I feel makes the question clear:
function ...
2
votes
1
answer
335
views
Why does the SIGCHLD generated by process continuation not activate the trap?
I am using linux (Ubuntu) and bash.
I made a simple Go program. Literally infinite for-loop that prints text every 20 seconds.
package main
import (
"fmt"
"time"
)
func ...
0
votes
1
answer
129
views
How I can run a php inline script and also provide command line arguments using bash?
I try to make a simple script that pings a network connection:
#!/usr/bin/env bash
# Xdebug ip detector for docker
# Copyright (C) 2023 Dimitrios Desyllas
#
# This program is free software: you can ...
1
vote
1
answer
98
views
Is it possible to pipe command output to fd3 of another process?
Normally, we can pipe stdout to stdin as follows:
echo "This is going to stdout" | grep -o going
Suppose instead of grep I wrote a script that reads from both stdin and fd3, and then ...
2
votes
1
answer
163
views
Make parameter substitution in newline-separated string more efficient
The following code should demonstrate and help with testing inefficient Pattern Matching expressions in a Parameter Substitution for a newline-separated strings var vs. array.
The goal is to achieve ...
0
votes
1
answer
54
views
How to show the actual changes for rpl dry-run?
From the manual of rpl the -s option enable the dry-run mode, that is it simulates the substitutions without changing the real files.
If I try it I get the following output:
$ rpl --dry-run 'JLCPCB ...
4
votes
1
answer
371
views
Restore deleted bytes after a `wipefs` on Linux
After re-installing a Linux machine, I inadvertently ran wipefs -a on the installer pendrive:
$ wipefs -a /dev/sd?
/dev/sda: 8 bytes were erased at offset 0x00010040 (btrfs): 5f 42 48 52 66 53 5f 4d
/...
0
votes
0
answers
114
views
Play new playlist in Rythmbox at specific times using shell script
I want to change the playlist of music in Rhytmbox at some specific time, while the application is already running.
I have started with a simple bash scripts, to launch each playlist:
#!/bin/sh
kill $(...
1
vote
1
answer
142
views
Help figuring out how to handle errors in "mongodump" script
I have a simple bash script that's supposed to create a dump file from a database
docker exec -i container sh -c "mongodump --archive" > \
~/dumps/db-$(date + "%d%m%Y").dump ...
3
votes
2
answers
426
views
How to handle a missing environment variable set in `crontab`
I have a bash script that I need to be able to start from either:
cron
an interactive (logon) shell
This script needs to know whether it was started from cron, or started from an interactive shell. ...
1
vote
1
answer
145
views
xattr -c not removing com.apple.FinderInfo attribute
I was trying to solve the problem in this post, and it seems like xattr -cr . is not actually removing the com.apple.FinderInfo attribute, nor is xattr -c <filename> or xattr -d com.apple....
0
votes
2
answers
212
views
append newline to bash alias
Im finding great difficulty in adding a new line character to my bash alias in my ~/.bashrc file
alias mip="curl ifconfig.me/ip"
I want a newline to be inserted after the above script, so ...
0
votes
1
answer
146
views
With sudo, why are inline environment variables not read correctly without -E on some systems?
I have a bash script which logs into my bitwarden instance using the bw cli, in the following way:
test.sh:
#!/usr/bin/sh
set -e -o pipefail
bw logout --quiet || true
BW_CLIENTID=$(cat ./credentials....
1
vote
1
answer
183
views
Parsing msgcat merge conflicts into "nice looking" console errors using bash and assorted CLI tools
I was asked by @terdon to post this follow-up to a more specific issue I had and resolved over here.
Apparently my choice of tools has not been a particularly smart one, so I shall describe the use ...
0
votes
0
answers
120
views
How Do SSH-Launched Long-Running Background Jobs Detach Without nohup or disown?
When running a long-running command in the background over SSH from a non-interactive shell script, I noticed the process continues running on the remote machine without using nohup, disown, or ...
0
votes
1
answer
108
views
Sum Up Numbers For Each Iteration From If Condition In Bash
I need to sum up the numbers, carry forward the values and store in a variable on if/else condition in a loop in linux bash. I am only getting the last iteration value but not the whole sum.
In the ...
0
votes
1
answer
138
views
What are the steps from the moment you start the terminal to the moment the shell starts listening for keyboard input?
What exactly are the steps from the moment I start the pseudo-terminal (CTRL+ALT+T) to the moment the shell starts listening for keyboard input?
I know that it roughly goes in the way that the ...
2
votes
1
answer
266
views
Calculate byte offset for unquashfs
I'm trying to calculate the -o value for extracting an .AppImage file using unsquashfs on foreign architectures/OSs , but using objdump instead of readelf to make the solution more compatible with OSs ...
1
vote
1
answer
68
views
How To Use Quotes In Variable In Bash [duplicate]
I need to assign a command to a variable and execute it with variable in linux bash. The command executes fine from command line but not from the variable because of multiple quotes. I hope backslash ...
0
votes
0
answers
25
views
How to update variable in outer scope in bash [duplicate]
I was using ChatGPT, it genereated code with errors that I needed to fix. Now it seems that the code is correct:
#!/bin/bash
root_dir="$HOME/Zdjecia/Artykuły/"
earliest_date=""
...
0
votes
0
answers
90
views
PS1: tab completion or line break leads to cursor shift
I recently changed my PS1 in my .bashrc and I notice that my prompt has problems when the command line has more characters typed into than the number of columns of my terminal window. I also ...
1
vote
1
answer
65
views
Returning value from popup box in bash
I would like to call a dialog box from a bash script and have the value returned. I tried
set l = `xmessage -buttons Ok:0,"Not sure":1,Cancel:2 -default Ok -nearmouse "Is xmessage ...
1
vote
2
answers
187
views
Why does the kill command not work for SIGTSTP, but works for some other signals (SIGSTOP/SIGINT etc.)?
I have the following two simple programs.
Parent:
package main
import (
"fmt"
"syscall"
)
func main() {
attr := &syscall.ProcAttr{
Files: []uintptr{0, 1, ...
0
votes
1
answer
71
views
Commenting out a line item in a text file that my bash .sh file refers to
I have an ssh .sh bash script file i'm running on a cron to check website status. The bash script (when ran) refers to a local txt file for a list of websites to check if they're down or up. ...
2
votes
1
answer
214
views
Locale: Unable to get correct date (for Sunday of this week)
I did the following yesterday night (before midnight of Sunday in Germany):
Today's date
$ LC_TIME="en.GB.UTF8" date --iso-8601
2025-01-12
Today's date (day of the week
$ LC_TIME="en....
-2
votes
2
answers
339
views
Dangerous behavior of the `cd` built-in
I was plodding along, working on a shell script, and I've just learned something that I found surprising. I'm presenting it here as a Question because I'd like to learn if there's some way to avoid ...
6
votes
3
answers
1k
views
Is bash's expansion of unset parameters to the empty string documented anywhere?
The bash shell expands unset parameters to the empty string by default. However, I can't find official documentation stating this anywhere. Is it?
1
vote
6
answers
399
views
Move a lot of folders with spaces in the name
I have a lot of webpages saved in my Download folder and I want to move all html files together with its folder (for every "NAME.html" exists "NAME_files/" folder).
The big ...
0
votes
1
answer
197
views
Why does a SIGTSTP signal not handled by the parent move the entire group to the background (contrary to written in TTY demystified)?
I started learning about linux tty(s) and signals and ran into some trouble.
I am reading and using The TTY demystified as a reference.
I made two simple golang programs.
Parent:
package main
import (...
0
votes
2
answers
116
views
Different `dollars`! [duplicate]
When using the command echo $100, I got the output 00 while if I give echo $d00 as the command, it gives an empty line! Why? Is there a way inside for the bash to interpret the two differently?
2
votes
2
answers
1k
views
Why is the file changing before being written to?
On Kubuntu Linux, The Google Chrome browser adds a checksum to the file, preventing simply editing the file by hand. So I'm writing a script to add the checksum.
$ cat .config/google-chrome/Default/...
0
votes
1
answer
99
views
changed ownership on folders by user that defined in sudoers file
I have the following simple script that changed ownership on folders
more hola_config.sh
#!/bin/bash
chown -R hola:pola /home/darna
chmod -R 775 /home/darna
in /etc/sudoers I added the following ( ...
12
votes
2
answers
2k
views
How to automatically terminate shell scripts after 1 minute of no output
I need to run multiple shell scripts sequentially (s1.sh, s2.sh, s3.sh) with the following requirement:
If a script produces no output (stdout or stderr) for 1 minute, it should be terminated
After ...
2
votes
1
answer
348
views
How to programmatically kill a notify-send window?
I have a bash script that opens a window with notify-send. I would like to close that window when the script ends, but I can find nothing to kill.
The question is a duplicate of https://askubuntu.com/...
1
vote
2
answers
237
views
Bash script exits prematurely when calling another script inside it
I am trying to run a script which calls another script, but it does not seem to return to the script that called it.
The source script "backup-plex.sh" calls “Linux_Plex_Backup.sh” (whilst ...
3
votes
3
answers
246
views
How to quit from a pipeline "command1 | command2" while keeping a background subprocess launched by command1 alive?
Regarding the command cmd1.sh | grep "message", in which cmd1.sh is as below
#!/bin/bash
echo "message from foreground father proess$(date)"
setsid sleep 100 &
echo "...
1
vote
1
answer
143
views
Does bash listen for commands in canonical or non-canonical mode?
I have three small questions regarding the mode the terminal is in when bash is listening / waiting for my commands:
When bash is waiting for my command, is it running on a terminal that is in ...
0
votes
1
answer
251
views
Where is the tty line discipline exactly "logically" located?
I recently started learning about Operating Systems and the linux kernel. I was interested in terminals, so I started there, however, I quickly ran into a problem. I wrote a slightly longer question, ...