Questions tagged [bash-scripting]
Bash scripting is making scripts in the Bash shell language.
974 questions
4
votes
2
answers
180
views
Why can’t I remove a file inside a while-read loop with a Bash script?
I have a polling script that will occasionally pop out the name of a file to delete. The file to delete will always be located on an NFS-mounted filesystem.
So I wrote this Bash script:
#!/bin/bash
/...
7
votes
3
answers
652
views
How to use BASH variables with "local", but less bloated?
I have a lot of code with lines like the following:
local -r foo="$(bar)"
Just recently I discovered shellcheck and that warns about those assignments, because local hides the actual error ...
0
votes
0
answers
78
views
How to use NinjaRMM to run an application via API?
I have a script like this listed on the device:
{
"type": "SCRIPT",
"id": 67,
"name": "script.run_application",
"language&...
2
votes
1
answer
139
views
How do I write a script that logs me out and suspends a PC running Ubuntu 24 with LightDM?
I'd like to automate logging out and suspending the PC on Ubuntu 24 with LightDM.
I tried this:
SESSION_ID=$(loginctl | grep $(whoami) | awk '{print $1}')
loginctl terminate-session "$SESSION_ID&...
9
votes
10
answers
2k
views
How to compare numeric strings in Bash?
I am attempting to write a script depending on the version of Debian.
I have tried the following:
#! /bin/bash
DEBVERS=$(awk '{print $1}' /etc/debian_version)
echo "DEBVERS = " $DEBVERS
if [[...
2
votes
1
answer
180
views
Bash script iterate through directory and delete zip file
Good day,
I have a directory with all my customers. (Auto Electrical). Inside every customer's directory is another directory with every booking they have booked with me before:
-John_Smith
--...
2
votes
2
answers
189
views
Multiple result lines from bash feeding into multiple variables
I am new to Bash and wanted some help.
I have a command which produces four lines and I would like these lines to be fed to four variables, so i can use them in the next command. could someone please ...
0
votes
0
answers
60
views
Are xarg + cp vulnerabler to race conditions?
I'm experimenting with Docker images having 20-70 GiB in a single layer (yes, the software/compiler is so fat). To improve the download and decompression efficiency of Docker, I'm splitting this fat ...
0
votes
2
answers
120
views
preserve variable within bash script
I have a bash script I am using to deploy updates automatically. It also includes logs of when the updates have been run.
I have added the entire bash script below.
The issue I am having is within ...
0
votes
0
answers
95
views
Jenkins Groovy syntax not working for find command
I'm trying to use find command with a backslash on the command below at groovy syntax:
stage("ArtifactRename") {
sh '''find "./os/mcu/GNU ARM v10.2.1 - Debug" -name "\\...
1
vote
1
answer
88
views
The output of a bash command changes if executed by a script
~$ echo $(date +%a%d\ %X)
lun.24 17:40:28
~$ inode-1
thunar.desktop
lun.24% +17:40:40
~$ cat inode-1
#/bin/bash
# inode_check
xdg-mime query default inode/directory >> /home/<user>/f1;
...
-1
votes
1
answer
405
views
Will jq output valid json even if error?
Is jq guaranteed to always output valid json, even if it encounters an error while running? Error could be due to poorly formatted input, for example. Outputting valid json and not outputting anything ...
1
vote
0
answers
440
views
Store bash glob pattern in a variable
I can use syntax as below to list 6 files named a1b.md, a2b.md, a3b.md, x1y.md, x2y.md, x3y.md in a directory:
ls a{1,2,3}b.md x{1,2,3}y.md
I'd like to use something like this in a bash script; with ...
0
votes
1
answer
200
views
How to run ncat -zv without showing version on RHEL7?
Hi everyone and thank you in advance!
I used to run the following script with ncat Version 5.51 and it gave me wonderful formatting
[root@server user]# for i in "cat server_list" ; do echo $...
1
vote
1
answer
183
views
Exit code of a bash script when one of the steps fails?
So I have to run a basic shell script that is not much more than:
#!/bin/bash
call01
call02
...
call_N
If one of the calls fails (gets killed by the OS because it runs out of memory), what does it ...