156,878 questions
3
votes
1
answer
93
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
46
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
35
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
47
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
2
replies
32
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
52
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
57
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
89
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
38
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
32
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
74
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
113
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
46
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
401
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
118
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
131
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
34
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 ...
2
votes
1
answer
43
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
88
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
61
views
How do I feed stdin to an expect script to spawns a shell and collect stdout?
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
83
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
0
answers
63
views
Colon in bash regex [duplicate]
I am using regex in GNU bash, version 4.4.23(1)-release (x86_64-pc-msys) (git bash).
I am having an issue indicating a colon to the regex.
I am looking for the following string:
Date : 25 Dolahn(6)
...
2
votes
2
answers
119
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
159
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
79
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
145
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
73
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
148
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
81
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
182
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
77
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
184
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
112
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}';
...
-1
votes
1
answer
126
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
51
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:
...
3
votes
5
answers
197
views
Using a function to format any list of PATHs
I have this alias to format $PATH into one line per path:
alias path='sed ''s/:/\\n/g'' <<< "$PATH"'
I tried to specify the env var to list, like path $MANPATH but still with a ...
0
votes
0
answers
64
views
aws ec2 ubuntu : why a command works with terminal BUT not with user_data?
i lanched an ec2 instance (ubuntu), and i have a script which looks like :
#!/bin/bash
# works fine (even directly in terminal or via user_data)
hostnamectl set-hostname ${hostname}
# works fine as ...
1
vote
0
answers
137
views
Add new element stored in a variable to existing JSON array with jq
I am working on creating an adaptive card dynamically. I have the skeleton on the card in JSON and I want to add entries to it (each entry will be a JSON object inside the "body" of the ...
3
votes
3
answers
128
views
Converting a CSV file into a nested JSON file using ./jq
I am hoping I can get an answer on this question. I am using ./jq to convert a CSV file into a file of JSON objects. Each line of the CSV input represents a JSON object. A sample of the CSV input is ...
1
vote
8
answers
260
views
How to check if a file contains *only* a string
I'm trying to interact with an API which returns json and which uses pagination. Unfortunately, they don't give any indication when you're reached the end of the list, they just continue to respond ...
2
votes
3
answers
172
views
How to pipe a data file with multiples read values to a bash script with a delay between them? It is possible to display the info read from file
This is my main script:
#!/bin/bash
read -p "Name: " NAME
read -p "Age: " AGE
read -p "Country: " COUNTRY
echo "Your name is $NAME. You are $AGE years old. You ...
1
vote
2
answers
99
views
How to conditionally add elements to an array in shell script
In the below shell script, I'm trying to conditionally add elements to an array which is syntactically incorrect when checked in shellcheck.
#!/bin/bash
echo "Hello World";
HH=1
ARR=(
&...
1
vote
1
answer
133
views
php's readline() method adding weird line breaks when executed via shell?
So I have this really weird issue where I have the following dummy.php script:
<?php
declare(strict_types=1);
$prompt = "Hello there!".
PHP_EOL . "What do you want to know?"...
0
votes
1
answer
66
views
Syntax error near unexpected token 'elif' in bash concerning conda [closed]
I have a problem with my bash file: each time I launch the terminal, this error occurs:
bash: /home/hk/.bashrc: line 125: syntax error near unexpected token elif' bash: /home/hk/.bashrc: line 125: ...
2
votes
0
answers
106
views
Why does my C Docker runner script not detect runtime error? [closed]
I am learning to replicate an online judge system using Docker to run C code submissions in a sandbox environment. My bash script (running inside the container) is supposed to detect compilation ...
0
votes
0
answers
60
views
How to escape the backward \ in sed -i to insert to top of file [duplicate]
I have a file that I'm trying to put a spool command and the dos path as the first line:
To get the dos path from bash I use:
CWDDOS=$(pwd | sed 's/\//\\/g' | sed 's/\\c/C:/g')
and it gives me this:
...
-2
votes
1
answer
122
views
Bash Hackerrank Challenge solution is working on bash version 3.2 on computer but not on Hackerrank Bash IDE [closed]
Attempting to solve the "Lonely Integer" problem
HackerRank problem statement:
My solution
declare -i n
read n
declare -a numbers
read numbers
n=${#numbers[@]}-1
while [ $n -ge 0 ]; do echo ...
0
votes
1
answer
78
views
LaunchAgent refuses to run shell script despite throwing no obvious errors
This question is similar to LaunchAgent doesn't run shell script, but the solutions there didn't work for me as my situation is presumably much more complex.
I have the following Bash script:
#!/...
3
votes
1
answer
93
views
How to detect that RETURN trap was called from source?
I am writing a library and would want to detect where from a RETURN trap was called. Kindly consider the following example:
#!/bin/bash
on_return() {
echo "on_return: ${BASH_SOURCE[1]}:${...