All Questions
Tagged with bash-function or bash
156,863 questions
-5
votes
0
answers
51
views
Copy files and preserve some part of the folder structure [closed]
This question is regarding a basic bash script copying files.
I have the source folder structure as below.
folder1/folder2/folder3/folder4/folder5/text.txt
The destination folder structure is ...
-3
votes
0
answers
80
views
How systemd service will interpret sleep when the PC is turned off? [closed]
I have a script that does three things in a loop:
Do one thing when started
Wait one day (sleep 1d) and then do this thing again
Repeat while the processname is active
A quick example based on a ...
2
votes
1
answer
98
views
Bash date calculates time addition incorrectly [closed]
I am writing a simple bash script for computing time and date by adding seconds onto a random date that I give. It worked fine so far but going from 2016-03-13 00:00:00 to 2016-03-13 03:00:00 skips ...
0
votes
0
answers
63
views
keyboard backlight script not working well [closed]
Environment: Ubuntu 24
I'm trying to create a bash script to turn on/off the backlight after a period of time keyboard if no key is pressed.
It's working when I run it by hand, but when I try to run ...
0
votes
0
answers
98
views
Why does this bash script not execute the commands sequentially? [duplicate]
Given:
#!/bin/bash
set -x
cat <<EOF | while IFS= read -r LINE; do "${LINE}"; done
/usr/bin/bash
pstree -u "${USER}"
EOF
It outputs:
$ ./cat_while_bash.sh
+ cat
+ IFS=
+ read ...
3
votes
2
answers
74
views
Reading desktop notifications from the command line. Debian/Ubuntu
Running Ubuntu 24.04lts.
NOTE: I am trying to read the notification sent by he Discord app to my personal desktop notifications. When I notification from a specific sender, with a specific message, I ...
0
votes
1
answer
55
views
"...SSH Permission denied (publickey,password,keyboard-interactive)" when running python script as service on raspi [closed]
I have a python script that runs as a service on raspi, the script executes a bash script which then connects to a windows pc via SSH using a key.
I have successfully use the same code to connect to ...
2
votes
1
answer
53
views
GRUB audit script always fails on Ubuntu even after remediation (AppArmor parameters not detected)
I am trying to implement a CIS hardening rule on Ubuntu that requires every GRUB linux entry to include:
apparmor=1
security=apparmor
Audit script
#!/bin/bash
if grep "^\s*linux" /boot/grub/...
Best practices
3
votes
2
replies
92
views
How to efficiently bulk download from the internet archive
I want do download certain search results from the internet archive. I would like that the names of the resulted files and directories to be the title of the work -- idealy YYYY_<author>_<...
-1
votes
1
answer
105
views
How to give root access to Java Runtime Process? [closed]
I am trying to run a bash command through Java.Runtime.exec(), specifically coredumpctl.
I am only able to run the command on a bash terminal when I login as a root user, and this doesn't seem to be ...
2
votes
1
answer
168
views
How to do nothing with "for in" in Bash? [closed]
for in in Bash is setting variable. I need only the variable itself from this command.
for VAR in FILE*; do
something (hate it)
done
I plan to use this variable later, not in the block itself. Just ...
Best practices
1
vote
10
replies
170
views
Bash tool/function to replace an arbitrary literal string (not regex) in a file/variable
I want to write a small tool or Bash snippet that can be used like:
tool key value file
and it should replace all occurrences of key in file with value.
I tried:
sed -i "s/${key}/${value}/g"...
Advice
0
votes
1
replies
53
views
How modify script with adding second task?
This script adds a line to add custom.js to vivaldi browser directory:
#!/bin/bash
vivaldi=/opt/vivaldi/resources/vivaldi
moddir=$HOME/vivaldi-modding/
sudo cp $moddir/custom.js $vivaldi
sudo sed -i -...
6
votes
4
answers
145
views
awk command to subtract constant from a column and print results
I was working on a one-liner to subtract a constant value (e.g. 100 in this case) from a specific column using awk. So far I can manage to get to where I can print the last iteration only – which ...
0
votes
1
answer
88
views
How to open a firefox tab in the currently open window
I created a script that is run by cron to open a tab in firefox. It will open a tab in firefox, but the tab is a new window. If I have firefox open, I need it to open in the same window that is ...
5
votes
2
answers
153
views
Hex escape sequences in bash regex range have no effect
Here is a bash script:
#!/bin/bash
char=$'\x01'
if [[ "$char" =~ ^[\x01-\x20\x7F-\xFF]$ ]]
then
echo "Unprintable"
else
echo "Printable"
fi
The script ought to say ...
1
vote
0
answers
68
views
Disable touchpad script fails while copied output works
I downloaded Fedora 43 Cosmic (Wayland) and found no way to disable my touchpad (mouse is always connected). xinput and synclient seem to be X11 only. Touchpad Disable is a simple checkbox with KDE ...
0
votes
0
answers
71
views
Sorting behaviour difference running bash script in a console session vs cron job
I have a bash script that I use to gather the usage stats of my storage volumes and email myself the results. Done so I can keep an eye on unexpected changes in disk usage.
The relevant code that ...
1
vote
2
answers
60
views
Loop in Background not listed in jobs
I have the following script, which should read the output from another command and then wait for changes, syncing these to a target directory. I replaced the actual commands with sleep and cat to make ...
Advice
0
votes
3
replies
45
views
How does nohup know whether I'm redirecting output to another file in bash?
My question is not about how to use nohup to redirect output. I've been using it for a while. Let me first state that I use bash. I know that by default, nohup my_command redirects stdout and stderr ...
0
votes
2
answers
63
views
Keep conda environment of parent bash session when start a new bash session
Suppose my current activated conda environment is py314 on Linux.
When I start a new bash environment from the current one,
no matter via command bash, screen, or start vscode from command line,
the ...
0
votes
0
answers
67
views
git-bash gettext wrong encoding
I'm trying to translate my bash scripts using the gettext tools but I have a problem where the encoding seems to be wrong.
Let's say I have the following file called fr.po:
# French translations for ...
0
votes
1
answer
121
views
Fortran90 doesn't compile with gfortran
I am attempting to compile and run a Fortran 90 program using command line (bash). In the past, when I've run gfortran /path/to/file, a file a.out and a file program_name are created, and I can run ...
Best practices
0
votes
0
replies
42
views
When packaging a bash binary produced by Bazel, do I need to keep the rlocation/data location boilerplate?
I was trying to exercise with Bazel by packaging a deb package from a collection of scripts I'm writing to automate a few tasks at work. Right now, I keep them either in /usr/local/bin or \~/.local/...
Best practices
0
votes
1
replies
34
views
Best way to check for empty secret/variables in GitHub workflows
We've had troubes in the past trying to validate github environment against unset/empty secrets or variables. I've used bash scripts like [ -z "${{ secrets.mysecret }}" ] && exit 1; ...
1
vote
0
answers
83
views
Prevent TMUX exit on PTY OOM kill?
I have a high memory program (ML) that I want to run in a tmux session. However, if the process is OOM killed, the tmux session is also shut down. I partially solved it (using the below run-bg), but ...
Best practices
0
votes
7
replies
125
views
Does Bash support local variables in POSIX mode?
Does Bash support local variables in POSIX mode?
x=42
echo $x
foo() {
local x=43
echo $x
}
foo
echo $x
$ /bin/bash4 script
42
43
42
$ /bin/bash4 --posix script
?
-3
votes
0
answers
51
views
Error trying to get access token for system-assigned managed identity at particular instance else working fine
Encountering an issue where the access token is not generated at the intended instance when using a Linux VM with system-assigned managed identity to retrieve secrets from Azure Key Vault. This issue ...
2
votes
6
answers
422
views
Slow bash script using shuf. Alternative to shuf for better performance or poorly written script?
My goal is to get a certain number of values between 1 and 50, a certain amount of times. It has to be randomly selected in [1-50] interval. I wrote this script but it runs awefully slow. I removed a ...
4
votes
4
answers
132
views
Map unknown associative array element
How can I map an unknown value alongside other known values in bash using an associative array, so that:
#!/bin/bash
array=("foo" "foo" "bar" "something else" &...
2
votes
4
answers
139
views
Is it the tty, the shell, or both that is responsible for echo-ing user input?
I seem to be observing conflicting evidence regarding how the tty and the shell share responsibility for displaying user input.
In the following interactive session, user input is no longer echoed to ...
0
votes
2
answers
39
views
Git Bash can't recognize flutterfire command on Windows OS
I have installed Firebase CLI on my Windows OS machine,
I have activated FlutterFire CLI, and have added Dart’s global bin to my system PATH
But when I run flutterfire --version command in my bash ...
1
vote
1
answer
48
views
terminals don't open in the new workspace, instead open in current workspace | i3 window tiling [closed]
i create a script that is supposed to create a new workspace and that workspace launch four terminal each in given position with a command ran in it.
this is the script.sh
#!/usr/bin/env bash
WS='9:...
2
votes
1
answer
93
views
How can I capture the output of a subprocess (deno) called from a bash script when run by CRON?
I have a bash script that turns off stdout and stderr when not run interactively (i.e. run from CRON).
if [[ ! -t 0 && ! -t 1 ]]; then
#echo "The script is not called ...
1
vote
1
answer
76
views
How do I feed standard input to an Expect script to spawns a shell and collect standard output?
Consider the following Expect and Bash scripts:
spawn-bash.exp
#!/usr/bin/env expect
spawn bash
stty raw -echo
log_user 0
remove_nulls 0
expect {
-i $spawn_id "?" {
send_user -- [...
1
vote
1
answer
92
views
YQ: load a text file as array and use it for an operation
I have a yaml file with an arbitrary amount of documents, and I'm trying to replace all missing namespaces for namespaceable resources with an arbitrary input one.
Getting the non-namespaceable ...
2
votes
2
answers
126
views
How do I operate on continuous piped output from a bash command?
I'm trying to write a small bash script that will take values from my mouse's horizontal scroll wheel to change my system's volume.
Using this guide, I've come up with the following command to ...
3
votes
4
answers
165
views
Array elements in sed operation
I am trying to replace elements on an array using a sed command to compare values between two arrays and replace them accordingly, with the following terminal input:
#!/bin/bash
icons=("" &...
1
vote
1
answer
81
views
Weird prompt rendering with custom $PS1
The question closely follows this one, except that I did what the git-prompt.sh does myself.
However, I started noticing weird rendering issues, where long lines do not wrap on the next console line, ...
1
vote
0
answers
153
views
Bash script returning whole array instead of single element
I wanted to make a CLI tool that will display a random quote (from a list of .sh scripts which show ANSI art along with said quote) and also let you filter by author.
It works fine when I pick an ...
1
vote
0
answers
76
views
UI tests blocked by “bash requesting screen access” popup in Mac OS
On macOS, I get a system popup when running UI tests in GitHub saying:
“bash” is requesting to bypass the system private window picker and directly access your screen and audio.
How can I disable ...
5
votes
3
answers
154
views
How to get the actual $0 as typed by the user in Bash?
When executing a Bash script from PATH, the $0 is set to some string that is equal to the full path of the executable.
Consider a script in /tmp/script.sh
#!/bin/bash
echo "0=$0"
echo "...
0
votes
3
answers
86
views
How can I display the colors of text inserted with color codes by another program in Bash?
When the text directly contained color code for example:
a="\033[0;31mRED\033[0m"
echo -e $a
The terminal had no problem colorizing the text in red. But when I modified the color code ...
3
votes
3
answers
188
views
git config alias function : Bad substitution
I have the following git alias function that moves files into a directory using git mv of those files and then does the git commit :
[alias]
mv-into-dir = "!mvIntoDIR() { \
cd ${GIT_PREFIX:-.}; \
...
0
votes
0
answers
80
views
Running bash script with Lua and Tup causes file permission issues
I am running a legacy C++ build env with Tup, Lua5.4 on Debian13. When I run tup, under any user (also root) there are strange file permission issues. When I debug and do and "ls -l" the ...
3
votes
6
answers
185
views
bash script use function call in string substitution
in a bash script I call an external script that gives me the status of a program, like
~/bin/status
which returns something like
program is running
or
program is halted
Now I want to use only the ...
3
votes
1
answer
117
views
bash script concat() in prepared statement for mysql
This gives a syntax error:
read -p "entry: " entry
sql="select concat('entry ', id) from mytbl where id = ?";
$mysql_conn "prepare stmnt from '${sql}'; set @id='${entry}';
...
-2
votes
1
answer
130
views
no visual active indication of python environment in linux mint terminal
i cant figure out why there is no visual indication that the python environment is active, i have created the venv with uv, i have installed the flet framework inside it and i can run the python file ...
0
votes
1
answer
100
views
Script to start the Rails server does not work when I use crontab
My script to start the Rails server does not work when I use crontab. I have a script to monitor whether Puma is running or not, and subsequently start the Rails server in production. When I execute ...
0
votes
0
answers
52
views
using xargs with git push --delete [duplicate]
I'm trying to manage a huge number of remote repos and I want to clean up the merged branches.
I do that with
git branch -r --merged HEAD | grep -Ev "(^\*|^+|master|develop)"
example output:
...