Questions tagged [shell-script]
Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.). Check scripts with https://shellcheck.net before posting.
16,784 questions
1
vote
2
answers
85
views
Dealing with stale mounts in shell scripts
I'm writing a bash script that archives logs from a folder where various servers dump their logs. From there, it moves them to one of three OneDrive mounts that are mounted with rclone (which I think ...
0
votes
2
answers
80
views
How can I read a single key press from a user if it's either the Escape key or a function key?
I'm writing a shell script that's aimed to be as portable and POSIX-compatible as possible, so usage of bash-only commands or high-level input libraries is undesirable.
I'm looking for a way to read a ...
1
vote
1
answer
114
views
Does the .bash extension exist? [duplicate]
I know and understand that scripts run through whatever I provide in the shebang at the top of the file. E.g.,
#!/usr/bin/env bash
And that the file extension is entirely irrelevant. But that isn't ...
1
vote
2
answers
143
views
How to run strace on a specific child process of another process automatically?
I have a closed-source executable (self-hosted Azure DevOps agent) that starts many processes. Among them is pytest. For debugging, I want to attach strace to the pytest process started by that ...
0
votes
2
answers
82
views
Automatic debian installation with startup script at the end
Hello I'm wondering how it is possible to add a final command that is executed as first boot once the system is ready.
Some of you have an example?
Just for a test I would like to do something simple ...
1
vote
1
answer
70
views
Automatically process newly downloaded archive folders (unrar, flatten subfolder, checksum, move to done)
I need to download many archives and I want a way to process them one after another.
I have a download program that reads files from an input folder and downloads archives from the internet into my ...
0
votes
0
answers
112
views
ssh-add: how to use SSH_ASKPASS program that itself requires input from stdin?
I have a keepassXC password store that contains both the SSH private key and its password.
In order to import it to ssh-agent in a headless setup, keepassxc-cli needs to be used.
To extract the key, ...
-4
votes
4
answers
213
views
bash pipeline: syntax error near unexpected token 'else'
I'm working on the following pipeline (codeshare.io/243VJE):
#!/bin/bash
#SBATCH --nodes=1 --ntasks=1 --cpus-per-task=10
#SBATCH --time=2-00:00:00
#SBATCH --mem=40gb
#
#SBATCH --job-name=pan_pca
#...
5
votes
3
answers
1k
views
POSIX sh alternative for bash's regexp matching
I am using this code to parse the first argument passed to my script. It error handles and it works just the way I want it:
if [ -z "$action" ]; then
printf "[${c_RED}ERROR${c_RESET}...
2
votes
1
answer
242
views
Replacing the domain string in the compiled binary file with an IP address
Just in theory: is it possible to replace the domain string in the compiled binary file with an IP address by editing a binary file in place with sed? (IP address belongs to a different domain, but ...
1
vote
2
answers
103
views
Sorting output from find more like tree --dirsfirst -F
Here is a sample directory tree as it would appear if it were sorted in character code order (i.e., directories are not listed first):
${PREFIX}/
.bashrc
.include.sh.d/
common.sh
...
11
votes
1
answer
1k
views
Is there any difference between [[ -n $1 ]] and [[ $1 ]] in bash?
The test [[ -n $1 ]] yields True if the length of string is non-zero.
But I've seen elsewhere and have tried using just [[ $1 ]] without the primary -n and it seems to have the same effect.
Is there ...
1
vote
1
answer
99
views
Bash: only the first long option is being processed [closed]
Suppose we have the file ./testing with contents
#!/bin/bash
# Flags
# Source: https://stackoverflow.com/a/7948533/31298396
TEMP=$(getopt -o ''\
--long first,second \
-...
2
votes
1
answer
122
views
Bash: function in a script with flags
Using https://stackoverflow.com/a/7948533/31298396, we can implement flags for a script testing as follows:
#!/bin/bash
# Flags
# Source: https://stackoverflow.com/a/7948533/31298396
TEMP=$(getopt ...
0
votes
4
answers
152
views
Mount a partition from a script unless it is already mounted
I would like to mount a partition of an external hard drive from a script using
udisksctl mount --block-device /dev/sda1
and in the end of the script I would like to unmount it.
However, it may ...