156,878 questions
0
votes
0
answers
97
views
Exit bitbucket pipeline step early if output condition is met
How can I exit the bitbucket pipeline step (as successful) early if a specific output is matched, and output a custom message. Otherwise just continue the normal output.
pipelines:
custom:
- ...
3
votes
1
answer
153
views
Need a test to see if sudo is already active (cached)
I need a bash script to check if 'sudo' WOULD be able to works without prompting for a password.
How do you best test for sudo as being ready to go and not needing a password because its session has ...
3
votes
1
answer
97
views
Why does declare reset the IFS in bash?
Why does this work to create an array out of the newline separated elements:
declare -a themes
IFS=$'\n' themes=($(plutil -extract 'Window Settings' xml1 -o - - <<< "$terminal_settings&...
4
votes
0
answers
197
views
How to make GPG make a GUI password popup when doing the Git commit signing
Every time when I was doing the GPG signed git commit (e.g. git commit -S -s -m "test"), the password prompt is in the CLI console. The password prompt before was a proper GUI pop up window ...
-4
votes
1
answer
104
views
How to force ImageMagick to not destroy file contents by overwrites? [closed]
How to make sure ImageMagic never overwrites files? To avoid this type of situation:
name1=$(identify -format '%[EXIF:DateTime]' input1.jpg)
magick -options... input1.jpg name1.jpg
# concurrently ...
2
votes
3
answers
235
views
VAR=$(< file) vs read VAR < file
I recently learned that there is a special case of command substitution:
The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).
I never use the cat variation,...
-1
votes
2
answers
172
views
Compare two big folders quickly in Linux, without caring about exact file diffs [closed]
So, I have got two directories personal_files and personal_files_oldcopy
Through some file processing, I am not sure if both directories contain the same structure, or additional / missing files are ...
0
votes
2
answers
152
views
Using bash variables instead of files as input to git commands
I have a script which sets useful git settings and aliases, and I want to end by printing the difference between git config --global --list before and after. I'd like to show the diff in the same ...
0
votes
0
answers
114
views
Create dashboard and widgets with graylog 6.3 API
I want to create Widget through bash script and Graylog 6.3 API
But I didn't find the proper new API for that, like the old versions.
i have created the input, stream and
then search and dashboard(...
0
votes
1
answer
82
views
Bash script having custom functions not running under systemd service [closed]
I have this script to get images from a webcam & process them via RKNN NPU
#!/bin/bash
# Define the temporary directory for images
TEMP_DIR="/media/32GB/pics"
# Define the resize/...
2
votes
1
answer
165
views
${parameter:?} to return instead of exit?
When writing snippets, I got into the habit of using expansions, such as:
#!/bin/bash
echo "You have provided ${1:?} as command line argument."
declare -r x=${1:?} # from now on, x is ...
0
votes
0
answers
110
views
Why does kubectl logs --follow show duplicate output when used in a loop to watch Kubernetes Job logs?
I'm running a Kubernetes Job from a Jenkins pipeline and want to stream its logs until completion.
I currently use this pattern in a Bash script:
job_status_cmd_complete="kubectl get job ${...
1
vote
1
answer
118
views
Bash logging out on login in tty
I wrote simple pam module to ran my own program, when session was created. When I login in GUI (by SDDM), everything works. Problem occurs, when login on tty (CTRL+ALT+Fn). In this case, bash wrote ...
0
votes
1
answer
99
views
makefile calls a shell script but it doesn't recognize the first argument passed
I have the following script and makefile:
Makefile
WORKING_DIR := /home/user1/working_dir
outdir := /home/user1/working_dir/outdir
script := ./myscript.sh
my_target: file1.ini file2.ini file3.ini ...
1
vote
1
answer
200
views
How to trap RETURN in a sourced BASH script from Zsh
I am writing a script that must be sourced and that I use daily in the terminal (zsh), and the solution to one of a problem in the script is to unlock a flock lock, I would do it in the trap for ...
0
votes
2
answers
122
views
How to get return value from a function when the output is assigned to a local variable?
I can get the return value from a function foo without problem such as:
$ cat test.sh
#!/usr/bin/bash
foo()
{
echo "hello"
return 20
}
bar()
{
x=$(foo)
rc=$?
echo $rc
}
bar
...
4
votes
1
answer
100
views
How to check if trap is ignored?
Subshell traps show parent traps with trap -p, but do not execute them.
Is it possible to get the "do not execute them" state? when trap -p returns the parent state? Do I have to track trap ...
4
votes
1
answer
102
views
How to return variables from a curly brackets scoped code?
How do I return variables from curly braces?
For example, how do I get the return value of the command curl outside the curly brackets in the following snippet?
#!/usr/bin/bash
{ # scope for tee
...
-2
votes
2
answers
162
views
How bash handles/difference signals in heredocs?
I currently making a project to write my own shell, a very simple one, but i got stuck on how I can differentiate a SIGINT signal received inside a heredoc and while interactive mode.
In bash, ...
-1
votes
1
answer
167
views
Using sed to extract second apperance of a block [duplicate]
I have the following source file named test.txt:
text before
---BEGIN MARKER---
content 1
---END MARKER---
text between
---BEGIN MARKER---
content 2
---END MARKER---
text between
---BEGIN MARKER--...
1
vote
2
answers
96
views
Date calculations in bash and trying to assign the output in env vars [duplicate]
I'm trying to do some date/time calculations in bash that don't work as expected at the console and when I add them to environment variables, I get very odd results.
As an example:
$ date
Thu Jul 24 ...
1
vote
1
answer
108
views
Add new element to existing JSON array with jq in a shell script: problem with variable expansion
as described in "Add new element to existing JSON array with jq" I am using this jq form to add elements to a JSON array.
This works fine in the command line. Short minimal version here:
jq '...
1
vote
0
answers
128
views
Using BASH's brace expansion to build file lists in RPM spec files
I have a strange problem with BASH 4.4 and RPM 4.13.3:
I used (extracts only)
%prep
%define template_list template{,_{AFC,AIC,ALC,CCT,CRC,GLC,ILC,LPE,PPI,PPO,PWC,\
SPE}}
#...
%build
for file in %{...
0
votes
0
answers
37
views
Doing a negative pattern-match inside a bash script [duplicate]
I'm trying to get a list of files that don't match a pattern -- in this example, scripts that do not end in .csh. This works properly on the command line:
ls ~/bin/!(*.csh)
However, running that ...
0
votes
1
answer
153
views
How to run WSL bash functions from CMD
In Windows cmd you can run wsl commands just by typing:
> wsl pwd
/mnt/c/Users/user/
But when I try to run functions that are stored in ~/.bashrc file, nothing is happening:
> wsl test
>
...
2
votes
4
answers
136
views
Can't get `sed` to work with text containing escape sequences
I want to be able to use sed (POSIX) to replace some text in the output from a command with a different message that includes escape sequences to allow me to set the colour.
To illustrate the problem.
...
2
votes
2
answers
161
views
why this bash script works?
git diff normally will not generate an output, if the two commits it compares are identical, to make it generate explicitly "the two commits are the same", I found the bash script below.
...
2
votes
7
answers
163
views
Modify a column with awk and a bash script
I have a test.txt file looking like this :
a,1,A
b,2,B
c,3,C
d,4,D
e,5,E
f,6,F
I want to modify the second field with some condition :
if value is 1 I modify it to 1_PLUS
if value is 4 I modify it to ...
-4
votes
1
answer
102
views
Stop Bash on Windows from interpreting string as a path
just having a play around with Bash to automate some things (I'm by no means an expert!) but am having trouble with some syntax.
I'm using the AWS CLI to try and delete some log groups. I have the ...
0
votes
0
answers
63
views
GitLab Runner with bash executor in windows failing to load bash profile
I see this error in gitlab runner job when im trying to use bash executor:
Running with gitlab-runner 17.11.0 (0f67ff19)
on xx-shell txxxx, system ID: 123
Resolving secrets
Preparing the “shell” ...
0
votes
0
answers
55
views
Difference in pipeline output behavior of zsh vs bash [duplicate]
I am confused by a difference in the behavior of bash and zsh when running the same simple piped command in both of them.
When I run sleep 4 | wc < text.txt in bash, I get 0 0 0 as output instantly ...
0
votes
2
answers
135
views
printf special character in interactive shell, but not from shell script
I'm trying to print a special character from a Shell script. printf '\U002F' works in interactive shell, but not from Bash shell script. Shell script keeps printing \u002F. I tried to escape \, but it ...
-1
votes
1
answer
174
views
How can I make awk print a text string followed by the entire line piped from a previous command?
I have 8 blocks of code: this, with a different path and site name. My goal is when the first word of the return is something other than "Success:" print the entire line, preceded by the ...
0
votes
1
answer
96
views
Applicable for use in a bash script match substring as whole word only in parent string?
Applicable for use in a bash script match substring as whole word only in parent string?
For example parent string:
A='enp1s0 enp2s0 enp3s0 enp4s0 lo tailscale0'
And substring:
B='enp1s'
I have ...
0
votes
2
answers
154
views
Temporarily export all shell variables & functions for a single command?
I want to know if there is a (hopefully simple) way to export all bash functions and variables for the scope of just one command. Much like how you can env VAR=VALUE cmd in bash but export all ...
1
vote
1
answer
78
views
Understanding IFS and -d:
if I run
while read -r -d: path; do
ls $path;
done <<< "${PATH}"
I get the right output.
But if I run
while IFS=: read -r path; do
ls $path;
done <<< "${...
1
vote
2
answers
110
views
Date Comparison in UNIX Shell Script failing
I am trying to extract the file date from the output of a gsutil ls -l command and compare it to other dates. However, the comparison appears to be not working.
lstr=$(gsutil ls -l gs://input-bucket/...
4
votes
4
answers
241
views
Dynamic precision in awk printf using shell variable
I think this is simple, but it's not working for me.
This is what I have.
float=$(awk -v res="$result" 'BEGIN {printf "%.2f", res / 1000}')
I want to use a variable to set the ...
0
votes
1
answer
97
views
Can I use t with drawbox to simulate a playhead over a waveform in a generated video?
I want to simulate a playhead moving over a waveform, like when playing a track in an audio editor. As far as I understand, I can generate this effect if I have both the audio file and an image of the ...
0
votes
1
answer
95
views
Text-formatting: Replace tabs with spaces in text/config file and keep the pretty formatting / reformat it via script (Python or BASH)
not sure how to categorize the following issue, I thought about relating it to BASH or Python first, but actually it's rather language-independent imo...
Anyway, I was searching but couldn't find any ...
-6
votes
2
answers
169
views
How to make read function print everything but a new line in Bash script [closed]
I want the read function to print anything but the new line when using in Bash script.
I tried the following code, but it does not help. It still prints the new line.
Minimal reproducing code:
#!/bin/...
5
votes
1
answer
139
views
Create a detached process in linux (shell) to avoid an uncatchable signal
Context : I am making my own cloud save manager for my non steam games, I am in the process of implementing a wrapper that launches games but also loads file from the cloud before opening and when you ...
1
vote
1
answer
112
views
Is it possible to use unicode quotation marks as ascii quotation marks in Bash?
In Chinese, the single quotation marks are ‘ and ’, and the double quotation marks are “ and ”. In daily work, I need to switch between English and Chinese input methods in order to write different ...
-3
votes
3
answers
120
views
Having trouble wrapping my mind around escaping when using the eval command
prepend() { [ -d "$2" ] && eval $1=\"$2':'\$$1\" && export $1; }
So I came across this function and let's say I run it as
prepend PATH /home/xyz/bin
Now, I am not ...
0
votes
1
answer
61
views
Trying to convert script so it copies subfolder contents into individual 7z archives [closed]
The issue I'm having is this, in the current directory I might have multiple folders like: "Aburner", "Btoads", "and "gigawing", each with multiple files inside of ...
2
votes
2
answers
83
views
How to match a "given character or nothing" in an rsync exclude field?
Can I simplify the following command in a single --exclude field?
rsync --exclude .[tT]rash*/* --exclude [tT]rash*/* <omissis>
The following seems to work but does include 'wtrash' (and other ...
1
vote
2
answers
145
views
How to 7zip each file individually without the file extension included in the archive name?
I am trying to organize a large group of files for use with another program that can run them archived but only if they are named for example "My Document.7z" and not "My Document.txt....
0
votes
0
answers
73
views
Segmentation fault when running sstp-client in docker container
I have access to MariaDB, which I can reach only through an SSTP VPN. I wanted to create an additional container in docker-compose and share the network with the application container. I wrote the ...
0
votes
1
answer
220
views
keepalived check_script does not run as expected
I have two VM's running keepalived. I have created a vrrp script to check if a container is running and if not decrease the priority of the vrrp node so that it causes a failover.
However on the ...
0
votes
2
answers
138
views
How can I run mpv as a detached process on files selected by fzf?
I have the following function
play-music()
{
local selected=$(find "${PWD}" -mindepth 1 -maxdepth 1 -type f -iname "*.mp3" | LC_COLLATE=C sort | fzf)
local processed="...