Questions tagged [shell-script]
Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
16,569
questions
2
votes
1
answer
140
views
How to detect if headphones are plugged in for a shell script?
I'm writing my own custom status for i3/Sway that shows a volume indicator, and I've run into a snag.
I'd like to know if there is a standard way, using standard Linux tools--maybe ALSA or sysfs--to ...
-1
votes
3
answers
70
views
Count number of characters per line
How can I effectively count the number of characters per line in a txt file, and then identify which lines have character counts that do not match a specific target number?
0
votes
1
answer
15
views
How to start tree of applications with dependencies
I need to be able to automatically start a requested application.
Every application can have pre requisite applications that need to be started before it starts, and an application can itself be a pre-...
2
votes
1
answer
313
views
Can one execute a function in background from a function that is already running in background?
Considering the following script:
if [[ -z "$DOWNLOAD_ONLY" || "$DOWNLOAD_ONLY" = *conditions* ]]; then
function get_condition {
curl -s "https://conditions.com" | ...
0
votes
1
answer
48
views
removing first and last character and empty spaces from a json file [closed]
I have given sets of different input files as shown sample below
cat out.txt
[
{
"regional_unit": "node",
"source_name": "1753250187_SPS",
"...
2
votes
3
answers
167
views
In bash, how to capture stdout and the exit code of a command when the -e flag is active?
To capture stdout and the exit code when the -e flag (exit the shell immediately when a command fails) is not set, I would use
OUTPUT="$(my_command)"
exit_code=$?
To capture the exit code ...
-1
votes
1
answer
38
views
Formatting the input file with Sed to Output but generating empty gilr [closed]
I’m having an input file with one million records and formatting and writing to another file to a different location but some times it is writing empty file(intermittent).
Following is the scenario:
...
2
votes
3
answers
384
views
Replace prefix string from lines in a file, and put into a bash array
In the file groupAfiles.txt are the lines:
file14
file2
file4
file9
I need a way to convert them to remove file and add /dev/loop and put them all in one line with a space between them.
/dev/loop14 /...
0
votes
1
answer
39
views
Format output and columms
In Linux in Bash in a for loop i do:
... ; do echo "$i --> $i-new" ; ...
The output is than something like this:
file1 --> file1-new
file2 --> file2-new
...
file9 --> ...
0
votes
0
answers
33
views
Script with command as different user
I am trying to run the following script in Ubuntu -
declare -a loggedOnUsers
readarray -t loggedOnUsers < <( w -h | awk '{print $1}' )
for loggedOnUser in "${loggedOnUsers[@]}"
do
...
6
votes
1
answer
394
views
How to avoid stdout and stderr out-of-order when pipe is used?
Initially, I want to log a program (actually rsync, or diff, or others, illustrated by function prog() below) standard output, standard error, and combined output and error (namely stdall) into ...
0
votes
0
answers
34
views
How to run script ONLY when trigger on wired and wifi?
I read a lot of examples on the internet. I put the script
/etc/NetworkManager/dispatcher.d
/etc/NetworkManager/dispatcher.d/pre-up.d
but the script does not work, that I want.
I want a script to ...
0
votes
1
answer
33
views
Symlinks with data inside directory
I'm using this symlinks
ln -s "$REPO_DIR/src/packages/my-project/out" "$OUTPUT_PATH"
Currently, my OUTPUT_PATH only has only 1 folder out
How can I make my OUTPUT_PATH has all the ...
-2
votes
1
answer
59
views
Associative Array contains filenames and paths
I have a pipeline that deploys scripts into a temporary dir. I need to rellocate them into their actual proper directory.
#!/usr/bin/sh
DEPLOY_HOME=/opt/xxx
function getDeployedFiles {
ls ${...
0
votes
1
answer
30
views
Script bash - Insertion of data into MariaDB from Oracle database
This script bash makes the data extraction to Oracle DB (another server), processing it and insert into MariaDB (my server), but the insertion it's misaligned and let it some columns in blank.
This ...