Questions tagged [shell-script]

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

Filter by
Sorted by
Tagged with
0 votes
0 answers
8 views

how to connect cd drive via usb port android using termius?

lsusb says doesn't have access to usb or doesn't read usb unauthorized user chmod doesn't let me install my user credentials or recognize me as the owner/user of the device and accounts although i am ...
Luma Veloce's user avatar
2 votes
2 answers
216 views

Execute copy commands from file

I have a DE_CopyOldToNew.txt file with a whole bunch of copy commands for copying old file names to new file names. The file contains rows like : cp /migrationfiles/Company\ Name\ GmbH/2014.138_Old\ ...
Rico Strydom's user avatar
2 votes
2 answers
179 views

How to generate a Lookup table or data struct and perform a loop over it in Bash

I am working on an embedded linux. I want to write a bash script that automatically fixes partitions. I have declared an associative array where the key is the mount point and the value is the device ...
DEKKER's user avatar
  • 926
2 votes
0 answers
34 views

Systemd - run bash script after user login on specific days

I use the i3 window manager and every day of remote work I would like to run a script that is responsible for setting up my monitors. On Tuesdays, I work onsite, then I'll want to run another script. ...
A.J.'s user avatar
  • 21
0 votes
1 answer
27 views

How do I start tmux with N equally-sized, vertically-split panes given an arbitrary list of startup directories?

I want a shell script that will launch tmux with N equally-sized, vertically-split panes, each with its own starting directory, where N is determined by the number of starting directories specified. ...
David A. Pimentel's user avatar
0 votes
0 answers
27 views

I want to print the actual gio launch command (e.g.)$ echo " gio launch /usr/share/applications/abiword.desktop" would print: $ Exec=abiword

I am aware that I could just use something like : grep Exec= /usr/share/applications/abiword.desktop I could also do something like: abiword=$(grep Exec= /usr/share/applications /abiword.desktop) ...
Titus Groan's user avatar
12 votes
1 answer
2k views

Odd inconsistency between executing and sourcing Bash script

I know this is not a very descriptive title (suggestions are welcome), but the fact is that I've been pulling my hair over this for hours and I have no clue where the root of the problem might lie. I ...
mesr's user avatar
  • 399
0 votes
1 answer
42 views

Script that reads input from terminal. How to tell the script to print to both tty and stdout in case it is called with a stdout redirection?

I have a script which asks users for input in the terminal, therefore in case the script is called with stdout redirected to a file, the user has no context on the prompt. So I would like to duplicate ...
Whimusical's user avatar
-1 votes
2 answers
97 views

What are some common uses for `run-parts`? [closed]

run-parts executes all programs and scripts in a directory -- but when do I need it? What are some common uses for it?
PetaspeedBeaver's user avatar
0 votes
2 answers
23 views

How do I run gnome-terminal passing in arguments to a command and keeping the command window open and interactive

This works with xterm (see https://unix.stackexchange.com/a/739977/119816) xterm -e "echo hello; bash" but doesn't with gnome-terminal. What is the equivalent way of doing this with gnome-...
PatS's user avatar
  • 604
-1 votes
0 answers
76 views

Bash loop help returning value from query

I'm new to bash and not sure how to do this. I'm trying to query a set of VMs in Azure. Once I have the VMs, I want to append a new "tag" to their tags field. Here is the current command I'm ...
Braden's user avatar
  • 11
0 votes
0 answers
18 views

Get fullname of downloaded Python wheel, without merely watching the filesystem

My script downloads a "continuum-transfunctioner" wheel from a pypi server as follows: python3 -m pip download continuum-transfunctioner -i https://pypi.acme.com:8080/simple --no-...
Olumide's user avatar
  • 177
1 vote
1 answer
26 views

Azure CLI bash loop not working

I'm trying to learn bash and become less PowerShell dependent but running into issues with what seems like an easy loop. Below is my attempt to get the loop to return each VM result with it's ...
Braden's user avatar
  • 11
-1 votes
2 answers
88 views

Test for substring in posix shell .sh script (NOT bash)

I use an .sh script to read the installed firmware of a controller and to compare it with the available firmware (and update on the controller if needed). To make sure the readout works I want to test ...
Serakis's user avatar
-1 votes
1 answer
97 views

Flag parameter in bash script misunderstood as file , “no such file or directory"

I’m writing a simple bash script named video2png, using the ffmpeg to turn certain frame of a video into png: #!/bin/bash ffmpeg -ss 30:00 -i "$1" -frames 1 -s 1280x880 -f image2 "$2&...
Wu Eureka's user avatar
0 votes
0 answers
32 views

How to use a remote ssh output as an input into a scp

I have a list of systems and I want to copy a log file out of many logs files, to my local machine which has a specific date of logs. for i in `cat serverlist`; do scp $i:$(grep -lR "2024-01-01 ...
user3038195's user avatar
0 votes
1 answer
31 views

Terminate batch job quietly

What signal code do I use with the kill command to terminate a background job quietly? Or perhaps an environment variable setting in the batch environment? Specifically, the "[1]+ Terminated ...
John-L_.'s user avatar
1 vote
1 answer
55 views

Bash parameter substitution with multi line error message

I'm using parameter substitution with an error message, such as ${var1:?'some message'}. I've incorporated a multi-line error message. Presently, it only functions properly when enclosed within single ...
programmer Erfan's user avatar
0 votes
1 answer
66 views

How to stop the while loop after four hours in shell script, if the file not found?

I am working on the ksh script where I am getting the file from the sftp server & copying to local & checking if the file is available there or not. I am running this on loop if the file is ...
ImSahil's user avatar
0 votes
1 answer
77 views

How can root get access to SSH_TTY

I think that SSH_TTY is an environment variable set by ssh that holds the device node of the current virtual terminal; e.g. /dev/pts/0, /dev/pts/1 , etc. I know that when I'm logged in to an SSH ...
Seamus's user avatar
  • 2,885
3 votes
1 answer
195 views

How to code defensively in Bash for unhandled runtime errors within logical expressions?

I just encountered an error where a function was missing in my script. I already trap and raise these exceptions to stop the script early, but I noticed that did not occur. Investigating this further, ...
Zhro's user avatar
  • 2,669
0 votes
1 answer
51 views

find with execdir, pipe redirection evaluated too early (quote issue?)

I use multiple GitHub accounts at work, so I need to modify the remote url to add my work account. I have figured out the recursive find -execdir, and how to get/sed/set the remote url, but I cannot ...
Robert Altman's user avatar
0 votes
1 answer
39 views

How to run snmpwalk using linux script

Basically i am new in the field of shell scripting and i want to run snmpwalk using linux script here is the script i have created: echo "Starting SnmpWalk" var = `snmpwalk -v2c CS IP 1.3....
Anubhav Kumar Panda's user avatar
0 votes
1 answer
58 views

Restoring bash prompt $PS1 to default

Is there a bash shell script or command that I can invoke to restore the original value to $PS1? I clobbered it without making a backup copy. If need be, I can always re-install bash, I'm hoping there ...
John-L_.'s user avatar
-2 votes
0 answers
56 views

Tcsh script for finding a corresponding value

I am trying to write a script to find out a pattern.  From a text file which has, let’s say, the following lines: Assertions Success: ...
suvash's user avatar
  • 1
0 votes
1 answer
42 views

openssl connect in a script

I'm using openssl s_client -connect to extract the dates from a cert. I want to integrate it into a bash script, the problem is that the command opens the connection to the server and waits for the ...
dejanualex's user avatar
0 votes
1 answer
36 views

How do I check if an IP-address or a network is contained in other network in BusyBox shell?

A BusyBox shell script has a list of IPs to be used as whitelist for a firewall ipset list. The whitelist may contain non routable IP's to be whitelisted. On the other hand firehol_level1 list (...
Pro Backup's user avatar
  • 4,904
1 vote
2 answers
49 views

Ensuring Distinguishable Exit Codes for Shell Scripts

Say I have two shell scripts, a.sh and b.sh, where a.sh calls b.sh somewhere inside. Then, say that b.sh could exit with exit codes 0, 1, or 2. What are some techniques that can be employed to ensure ...
Pacopenguin's user avatar
4 votes
2 answers
788 views

Combine two files as part of a command line parameter

I am trying to use csvgrep (part of csvkit) to extract rows matching one of two files. Unfortunately, there is no command line option that allows two matching files (like grep does). Only, csvgrep -f ...
Robert Altman's user avatar
0 votes
0 answers
25 views

Repeat a command with a variable taken from a file line by line [duplicate]

I am trying to retrieve a string of text from a file which exists on a bunch of remote servers. The servers all have a custom port number so I put those numbers in a file called "port_numbers.txt&...
trebuchet's user avatar
0 votes
0 answers
44 views

dhclient exit hook cannot write to directory

I am using RHEL 8.9 and have created a basic dhclient hook script in which I want to log to a file. The script is able to write to places like /tmp, but not /opt. It can read files from /opt, but not ...
trebor's user avatar
  • 111
0 votes
1 answer
52 views

How to detect if a process runs longer than X seconds, then do something with it?

I’m on debian. I am calling a ffmpeg process to generate a mp3. this gets called from a php script using shell_exec. This works fine 99% of the time. Sometimes, the ffmpeg process doesn’t exit and I’m ...
frumbert's user avatar
  • 115
1 vote
0 answers
76 views

Incorrect folder name created when using cp command in bash

I would like to copy a file from one location to another. When I use the cp command in a terminal it works well, for example I use the following command: cp -r projects/Test/ projects/Personal/ This ...
user601459's user avatar
0 votes
0 answers
29 views

Starting an application with a .desktop file right at system start: Why is it inactive after system start, requiring selection by alt + TAB?

All application startups set by GUI for current user sessions are stored as files at a certain place of per home directory: cd ~/.config/autostart Set an application to start up with every boot by ...
futurewave's user avatar
1 vote
1 answer
53 views

Bash script to open new terminal with path from current?

I am using zsh For example, i am in ~/Downloads, and want to run script, that will run new terminal with this path. What i did. work.sh #! /bin/bash current_path="$PWD" echo $current_path | ...
serii 's user avatar
  • 21
0 votes
0 answers
32 views

Output of python script like if it's typed in interactive mode

I have a python file and I want to obtain the output just like I'm typing the content in interactive mode (like this question https://stackoverflow.com/q/59008423 but with a shell script) I try with ...
Pablo Cárdenas's user avatar
0 votes
1 answer
53 views

How to hide a variable value when set -x is on

I need to use set -x in my script to show the executed commands in my log but there is a variable which is a password, so this password is showed in plan text Is there a way to hide only a variable? ...
Astora's user avatar
  • 429
2 votes
3 answers
744 views

Alternatives to file polling?

In the following code, I have to poll $tmp_input to continue executing the code because wezterm cli send-text is asynchronous. This makes sure that $tmp_input is ready. tmp_input=$(mktemp ./tmp_input....
wyc's user avatar
  • 133
0 votes
0 answers
41 views

How to gracefully handle differences in command options between different versions?

Inspired by What is the difference between “base64 -b0” in macOS versions prior to macOS 13 (Ventura) and “base64 -i” in macOS 13 (Ventura)? Are there common ways to avoid the script breaking on a ...
typo's user avatar
  • 229
0 votes
3 answers
82 views

If-else Parameter substitution

I'm running a series of experiments with bash and want to store the log files in a directory whose name is based on the experiment configuration. Some items in the configuration are boolean (true/...
Green绿色's user avatar
0 votes
1 answer
47 views

In zsh, Home, End, and Del behave differently inside a script than they do outside

I learned after much frustration that having $EDITOR initially set to vim doesn't affect the main shell but does affect scripts and nothing seems to undo this initial state. Unsetting the env var, ...
Walf's user avatar
  • 1,311
0 votes
0 answers
32 views

How do I execute a command but only add a *modified* version of it to the history?

I'm trying to create an analog of the command history, but for the output of the commands, so that I can do e.g. locate filename (which might display several files) and then vim %2 (or whatever) to ...
colinh's user avatar
  • 47
0 votes
0 answers
16 views

mount ext4 usb disk in /run/media/$USER/DISK-LABEL as user but not as root

I have found a couple of script using systemd to mount an usb disk. one udev script one systemd service script (which call the shell script passing the device name, the action to be done ) one shell ...
jcdole's user avatar
  • 1
-1 votes
4 answers
80 views

How to extract some part of the path in shell script?

I have a variable with path /usr/apps/app1/home/usera/run/10/_tmp/folder1/folder1. How can I extract /usr/apps/app1/home/usera/run/10/_tmp in shell script?
noonenine's user avatar
0 votes
2 answers
96 views

What happens when I give the shell a "command" versus a script?

A variant of this question has been asked a few times (here and here, for instance) but I'm afraid that the answers either didn't fully capture my question here or else perhaps assumed more than I ...
EE18's user avatar
  • 233
0 votes
1 answer
58 views

Portable alternative to `script(1)`

When I have to produce a log of a tool that responds to interactive input on the terminal (tee on stdout breaks this somehow), I reach for the script(1) tool, and it works more or less as advertised. ...
user22476690's user avatar
1 vote
0 answers
24 views

find subdirectories from different mount points without symlinks that have the same name as the subdirectory [duplicate]

I struggle to find a working find command, I hope someone has an idea. Imagine the following structure, where path and path{0..1} exist and they are each mounted from a network storage device: dir: /...
Oliver R.'s user avatar
  • 141
0 votes
1 answer
44 views

Adding an account via SSH not working with openssl

I am trying to add a user account to my remote server (running on Ubuntu 22.04) via SSH using below script: #!/bin/bash protect="y" ssh -i ssh_key [email protected] <<END sudo deluser ...
hiddeneyes02's user avatar
0 votes
0 answers
25 views

Reading from FIFO in nc (netcat)

I have a bunch of log files that I'd like to watch as they get updated. I came up with the script below: #!/bin/bash # Check if at least one log file is provided if [ "$#" -eq 0 ]; then ...
farhanhubble's user avatar
0 votes
0 answers
23 views

BASH + dig on list of domains gives wrong input to dig with domains suffixed with '\013' [duplicate]

I have a list of domains, and I want to use dig to check whether those domains have HTTPS records or not. I ran a for loop to do so, and I realized that the reason why I don't have any result is ...
cs.lev's user avatar
  • 1

1
2 3 4 5
328