156,881 questions
Best practices
0
votes
1
replies
27
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; ...
Best practices
0
votes
7
replies
91
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
?
2
votes
6
answers
332
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 ...
2
votes
4
answers
116
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 ...
1
vote
1
answer
41
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:...
1
vote
1
answer
58
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 -- [...
-2
votes
0
answers
61
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)
...
3
votes
4
answers
151
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
0
answers
136
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 ...
5
votes
3
answers
144
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 "...
3
votes
3
answers
180
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:-.}; \
...
3
votes
6
answers
174
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 ...
-1
votes
0
answers
37
views
Meson cross compile using git bash on windows
setup
host: windows
platform
git bash Installed meson via python, python -m pip ninja-1.13.0-py3-none-win_amd64.whl/meson-1.9.1-py3-none-any.whl
Want to do cross platfom compilation on a windows host ...
-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
0
answers
50
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:
...
0
votes
0
answers
57
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 ...
3
votes
3
answers
120
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 ...
2
votes
3
answers
164
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
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?"...
2
votes
0
answers
103
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 ...
-2
votes
1
answer
107
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 ...
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]}:${...
0
votes
1
answer
73
views
playing sound file when bash script is ran by cron task
below is a bash script that works fine tested in my terminal the sound is played but when it is actually ran in a cron scheduled task there is no sound only the dialog is shown
#!/bin/bash
export ...
1
vote
1
answer
101
views
Remote Command Execution and Cleanup
Goal
Execute long running command remotely with the following capabilities:
We can kill the task with its PID
If task completes, its exit code should be written to file
Task should be detached from ...
1
vote
1
answer
83
views
Printf command stops working when DEBUG trap is active?
When I set a DEBUG trap in Bash like this:
set -o functrace
trap 'echo "# $BASH_COMMAND" >&2' DEBUG
Suddenly, this function stopped working:
getBase() {
local base="$1"
...