Questions tagged [shell-script]
A shell script is a script written for the shell, or command line interpreter, of an operating system.
1,457 questions
5
votes
3
answers
2k
views
Bash script that waits until GPU is free
If my PyTorch training script is run twice at once, the second run will fail due to not having enough GPU memory.
So, I want a bash script that I call like ./scripts/wait.sh && ./scripts/train....
1
vote
1
answer
39
views
Run bash scripts on KDE Plasma sleep and wakeup events of Power Management as a particular user?
KDE Plasma 5.27.11 on Debian 12 amd64
I need to send some very short signals over USB on workstation's power management sleep and wake up events(not login and log out, they work fine). I have prepared ...
0
votes
1
answer
56
views
Returning a Value from an external operation in shell script in Linux?
I am writing a shell script in Bash. Within the Bash terminal I am using "CLI" commands to do some function. In this example I am creating a model, that if the syntax is correct, will ...
2
votes
1
answer
64
views
Create a visual diff between two images and overlay it on one of these using imagemagick
I have two images (of a schematic) and I want to highlight the differences on one of them:
Using imagemagick I can create the visual diff and I can also overlay it over the second image:
compare ...
0
votes
0
answers
124
views
How can I create a command to activate a Python virtual environment across different shells with minimal complexity?
I'm developing a tool that needs to activate a Python virtual environment using a custom command. Currently, I'm using the following alias in my .bashrc file:
alias activate_env="source ./env/bin/...
0
votes
0
answers
104
views
Bash script for opening multiple terminal tabs in Windows Subsystem for Linux
I need a bash script that opens multiple terminal tabs when executed.
Each of these tabs should also "cd" into a specific folder.
This is the script that works in Linux, but as expected, in ...
0
votes
1
answer
50
views
Can multiple command arguments into variable and be expanded back in POSIX script?
In a POSIX shell script is it possible to store multiple command arguments into a variable and then expand that variable later in a command?
For example, given the following code that pass arguments ...
0
votes
0
answers
119
views
How to perform a zuluCrypt "Create Encrypted Container in Hard Drive" but as a Linux command line?
I have long been in the process of converting my manual steps to create a new backup disks into an automated script. The only part I have left is the initial "creation" of the disk, meaning ...
2
votes
1
answer
93
views
Remove duplicate lines based on specific string
I try to remove duplicate lines based on specific string. There is two similar cases in my question.
I have this kind of file:
20151222051106 http://website.org/2015-12-11-art1
20151222054115 http://...
0
votes
1
answer
178
views
Why is exit status of grep not working in this script?
Here is the script:
echo a | grep b
if [ $? ]; then
echo b
fi
I expect it not to print anything.
5
votes
1
answer
375
views
Variable of a space-containing path causing issues in WinSCP commandline
I'm trying to automate some WinSCP SFTP transfers in a PowerShell script, while still keeping a lot of the relevant data stored in variables.
$outFileName = Split-Path $outFile -Leaf
$outFilePath = ...
0
votes
1
answer
86
views
Creating a shell script to automate tasks
Everytime I log into my VM I need to:
sudo openvpn file.ovpn
python3 file.py
ifconfig
sudo docker-compose up
I want to create a shell script to automate this. I don't mind having to type the sudo ...
0
votes
2
answers
147
views
bash + how to insert date before line
lets say I want to pipe the date output in the beggining of some text
for example
echo "this line is test line" | date
and expected output should be
Wed May 22 14:55:10 UTC 2024 this line ...
0
votes
1
answer
130
views
Execute a remote shell script from within screen via SSH and view stdout in one command
Couldn't find an answer for my particular use-case in the hours I've unsuccessfully researched this.
I have a script located on machine B. I am aiming to run a command on machine A that establishes an ...
2
votes
2
answers
580
views
Windows 11 PowerShell zip files except the excluded file and folder paths
I'm trying to zip using PowerShell but it's not excluding the files listed in the excluded_paths. I want to especially exclude all __pycache__ folder occurrences that can be nested in different levels ...
4
votes
2
answers
760
views
Windows Batch Script: how to recursively go through all files except certain file types and folders?
I'm trying to do a replace string operation on all files except those in .git folder and all pycache directories which can appear nested in any nested directory. I'm executing the script in the root ...
0
votes
1
answer
142
views
Why do string variables in a bash script behave differently when echo'ed than they do when passed to an executable?
I have the following script:
#!/bin/bash
KID3=$(command -v kid3-cli)
ARG1="-c 'get'"
file="'1-01 - Johann Strauss - __Waldmeister___ Ouverture.flac'"
echo Command:
echo "$...
0
votes
0
answers
611
views
how to use curl for single sign-on website or page
I've already written a shell script but it's not working. I'm getting an empty response whereas it should first return a token and also it should login then register the API.
That's the task which my ...
1
vote
0
answers
48
views
Pathname or word too long in Cshell
I am using cshell. And I know that there is a limit of 1024 character while setting path. But I have many path variables which I need to set. So, it is exceeding 1024 characters and I am getting an ...
0
votes
1
answer
39
views
shell helper function wrapping `find` and ignoring some dirs
I have a bunch of scripts which follow the pattern of:
find files which match a pattern
do something
The problem is that there are several "hazard" directories which are large and slow, ...
3
votes
1
answer
483
views
How to quick record system audio in background on macOS?
On macOS Monterey I want to achieve what can be done on Windows with ShareX: record system audio with a global hotkey and have the audio file automatically copied to the clipboard – all in the ...
1
vote
2
answers
290
views
Why does zip --exclude only exclude files in the folder but not the folder itself?
I have the following command run in the bash shell which excludes the files in the folder scripts/. I tried the answer in Zip command for excluding directories and files but unfortunately it did not ...
1
vote
0
answers
133
views
Zsh handling of substring changed?
I have over a thousand directories holding MP3 files and text. I work on one directory each day, assisted by zsh scripts. I mostly use zsh on command line and in scripts. The paths are in the form ...
1
vote
0
answers
56
views
Grub script how to remove menuentries
I made a grub script to detect bootable disks and show them on grub menu. It is working but I want to put a rescan button and to make that first I need to remove old menuentries. How can I do?
And if ...
0
votes
0
answers
160
views
TERM environment variable not set when running shell script using automator (MAC)
In using mac sonoma. I tried to run my shell script via Automator app. There's a 'diskutil umount' command in the script that will give me this error :
TERM environment variable not set.
Usage: ...
0
votes
1
answer
155
views
How to convert code from test format to if fi format?
I have code that opens a bash file in a terminal for entering the sudo password:
test "$IN_TERM" || {
export IN_TERM=1
konsole -e "$0"
exit 0
} && true
I need ...
5
votes
1
answer
476
views
Is there a good way to write a shell script compatible with both bash and zsh that addresses array elements?
The fact that bash is 0-indexed and zsh is 1-indexed can cause problems. For example the following will work as intended with bash, but not zsh (PS I am aware that I don't NEED to use an array for ...
1
vote
0
answers
3k
views
Termux can't run shell script
As stated in the topic above, I am trying to configure a hardware using shell script which is downloaded from the official website of Orange Pi. Am using termux as the medium to run the shell script ...
0
votes
1
answer
111
views
Having disabled command-Q for Terminal via shell defaults command, how can I re-enable it?
I have a large, complex console program for execution via Terminal which solicits many responses from the user. Users may be habituated to use command-q to exit a program. This program has its own ...
0
votes
0
answers
607
views
ffplay works from command line but error with .sh script and systemd
(Originally posted as a generic question, then I found the ffplay forum)
I'm trying to set up a daemon to play short sound effects as part of an interactive wheelchair ride. (Due for installation next ...
0
votes
1
answer
97
views
How deep is too deep for Nested Folders in a Bash program?
I am somewhat new to Bash and am writing a program to install .NET SDK and Runtime on each of the available Linux distros.
The problem I am having is that I am trying to source functions from two ...
0
votes
1
answer
79
views
zsh on MacOS catalina 10.15.17
I'm having a little trouble putting this all together...
I want to make a simple shell script to organize and sort around 60 GB worth of music and movie files that are spread out over 3 or for 4 ...
1
vote
0
answers
417
views
Source multiple files in background/parallel (ZSH)
For various reasons I would like to be able to source a series of files in background and wait for them all to finish:
source ./my_file_1.sh &
source ./my_file_2.sh &
...
# etc
wait
But, ...
0
votes
0
answers
28
views
Programmatically open new CMD and enter code *but not run it*? [duplicate]
Is it possible in Windows to programmatically launch a new instance of CMD, Terminal, or PS (doesn't matter which) and populate the input field with some arbitrary code, just like if a user was typing ...
5
votes
1
answer
480
views
Query effective ssh (client) config from the command line
Is there any way to query the effective ssh (client) configuration?
Specifically: can I determine e.g. whether there's an entry for a given host, what's the ProxyJump or User setting for that host etc....
0
votes
1
answer
69
views
Complex find statement
Have a script that I use to purge old backup directories. All the directories are named YYYY-MM-DD. The backup directories have links in them as the backups are incremental using the rsync --link-dest....
3
votes
1
answer
94
views
Is it possible to schedule "Alarms Only" mode in Windows 10 using a shell script?
I want to automate this to trigger every day at certain intervals, it seems so hard to configure a good notification system in Windows 10.
I would like to trigger the Windows focus "Alarms only&...
1
vote
1
answer
625
views
Maintain a fixed-size-queue of nohup jobs
Suppose I would like to run multiple nohup jobs but at each time I would like to at most run 4 nohup jobs.
Is there a way to:
keep track of 4 nohup job status
once one of them finishes, it triggers ...
2
votes
1
answer
176
views
Algorithm to find longest common substring
I'm having a bit of trouble coming up with a general solution to the following problem.
First a bit of context.
End goal: set file permissions on all files and directories created by a rpm
My plan was ...
0
votes
0
answers
952
views
Reference shell Script within a shell Script in YAML
Is there the right way to reference a shell script written within a script in a YAML file. For eg:
data:
ex1.sh: |
#!/bin/bash -x
. /shellscriptloc/ex2.sh
...
...
2
votes
0
answers
55
views
SFTP user login details real-time filtering
I have enabled the SFTP login log into the default logfile /var/log/syslog and tried to filter the login time of each user and insert it into the database.
But the filtering is not worked as I ...
0
votes
2
answers
873
views
Bash printf: what does format specifier %P mean?
The printf statement :
find directory1 -type d -printf "%P\n" | sort > file1
in the answer https://superuser.com/a/166322/856910 includes a format specifier %P. From the output of this ...
1
vote
0
answers
1k
views
how to print an entire get request from an API in Powershell?
I am working on a powershell script that displays all of the dns servers I manage via GoDaddy, and see which ones are about to expire. I am using the GoDaddy API and this following code:
. .\configs\...
0
votes
1
answer
860
views
Running shell Script via Systemd.timer
So I've essentially run into the same problem as in my other question: Running shell Script via Crontab
I will now run my shell script with systemd.timer but it is not working so far.
Here is my ...
1
vote
2
answers
1k
views
How do I run a bash script automatically everytime I hit CTRL + S?
I'm making frequent changes to a bash script and everytime doing "./demo_script.sh" is repetitive.
Is there any way that it can automatically execute as soon as I hit CTRL+ S on keyboard?
2
votes
2
answers
492
views
Why the variable doesn't change even if it should?
I have this bash script:
#!/bin/bash
someVar=0
tac /etc/hosts | while IFS= read line; do
echo "$someVar : $line"
someVar=$((someVar+1))
done
echo "Finally: $someVar"
...
-1
votes
1
answer
1k
views
I would Like to know what -sb and awk '{print $1}' role in this command
subdirectory_size=$(du -sb "$entry" | awk '{print $1}').
I would Like to know what -sb and awk '{print $1}' role in this command.
2
votes
2
answers
3k
views
Change the default location of zsh completion cache files for macOS
I'm trying to change the default location of the zsh completion cache files in macOS. I have read the zsh documentation on completion which say's "alternatively, an explicit file name can be ...
0
votes
0
answers
102
views
How to automate mybb installation using ssh bash script
I have created this bash script to install mybb application automatically on Centos stream 8.
SSH Bash script
#!/bin/bash
# Define variables for MyBB installation
DB_NAME=mybb_db
DB_USER=mybb_user
...
2
votes
2
answers
157
views
What options are being used by sed to parse a file and write to new file
I am debugging a LINUX script that was written by someone else. In the script we have a line of code like below
sed -i "\#</resources>#{h;s#.*#cat /opt/abc/new.xml#e;G}" /opt/abc/...