Skip to main content

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
1 answer
13 views

Use fallocate with numbers from text file

For testing i create at my Linux-System the file list.txt. In there are numbers like: 4 1 5 2 3 (sometime there are more or less numbers) How do i run these numbers with fallocate? fallocate -l ...
user447274's user avatar
-1 votes
2 answers
45 views

Using awk, append a value in last field in csv file based upon value in specific field

input.csv - "family_guy","Brian","b47f0a80-d848-4d81-a45b-7ba930e6048b","son" "family_guy","Brian","b47f0a80-d848-4d81-a45b-...
Raman Kathpalia's user avatar
0 votes
0 answers
10 views

Animating GIFs as previews in File Manager "LF" or "ranger"

The desired behavior: When I'm using a file manager "LF" I would like to have animated GIFs as previews when I am over an image/gif mime-type file. What I actually had on mind was to convert ...
Noa's user avatar
  • 31
1 vote
3 answers
86 views

Can I make a script that Reboots and continues after?

I currently have a script that I want to run #! /bin/bash Echo “plotting chart” systemd-analyze plot > boot.svg wait Echo “rebooting” shutdown -r +1 sleep 180 Is there a way to edit this so the ...
Squirrel's user avatar
2 votes
4 answers
786 views

How to POSIX-ly ignore "warning: command substitution: ignored null byte in input"?

Today, I was working with my Raspberry Pi 4 with Debian 12 Bookworm, and I found it odd, that some system text files, namely I needed these two: /sys/firmware/devicetree/base/model /sys/firmware/...
Vlastimil Burián's user avatar
-2 votes
1 answer
63 views

runuser: execute commands without use of quotation marks?

Overview I'm attempting to execute commands as a different user without using quotation marks as well as making sure the executed command isn't inheriting environment from the parent shell. runuser ...
GrabbenD's user avatar
  • 128
0 votes
0 answers
16 views

Run "scrot -" from Openbox

I'm trying to add a new keybinding to the rc.xml of my Openbox WM. The code is as follows: <keybind key="Print"> <action name="Execute"> <command>scrot -s - ...
Deeproad's user avatar
0 votes
0 answers
23 views

SLURM job script - why is the tmp local directory deleted before archiving can occur? How to prevent this?

I wrote a SLURM job script to run a computational chemistry calculation using the CREST program (part of the xtb software package). In the script, I create a temporary directory on the local storage ...
lay lay's user avatar
0 votes
2 answers
64 views

variable with hyphen in bash script

db1="community-service-data" db2="ecomm-data-test" drop_db="DROP DATABASE ${db1}" sudo -u postgres -S /bin/bash -c "psql -U postgres -d postgres -c \"${drop_db}...
CodeWeed's user avatar
  • 137
0 votes
2 answers
50 views

Bash script to compress nested directories not traversing correctly

I have a folder structure that looks like this: 0/1/2 and the numbers goes from {0..9} I tried writing a bash shell script so that I can compress each of the folders like this: #!/bin/bash for i in {0....
alpha754293's user avatar
1 vote
2 answers
73 views

Command not found on shell opening

Every time I open the shell, the first line on the terminal is "bash: n: command not found". I tried to look at /etc/profile, ~/.bashrc, ~/.profile and ~/.bash_profile but I was not able to ...
Alessandro's user avatar
0 votes
0 answers
24 views

Evaluate command inside comparison in makefile [duplicate]

I would like to check if Linux system is ubuntu inside Makefile. What I do is: copy_files: if [ "$(head -n 1 /etc/lsb-release | cut -d '=' -f2)" = "Ubuntu" ]; then \ ...
ellat's user avatar
  • 37
6 votes
1 answer
353 views

Why does redirecting stderr interfere with bash's handling of $COLUMNS and the `checkwinsize` option?

I'm scripting a testing framework in bash and am running into a weird situation. A couple things I'm doing in this post for illustration purposes: Adding echo lines to the scripts; these are not part ...
Targeloid's user avatar
  • 229
2 votes
2 answers
200 views

find with du -sch and very many files

I have large folder structure and need to get the size of a certain subset. The directories I need to count are defined by having specific subdirectories: find . \( -iname a -or ... \) -printf "\&...
cheersmate's user avatar
0 votes
0 answers
19 views

Setting variable (ORACLE_BASE) for oracle user | Installing Oracle 23

Goal: Install Oracle 23 into /u00/app (and not the default, /opt/oracle). Problem: Oracle installs into /opt/oracle (I assume the variable ORACLE_BASE etc. is not properly set / read for user oracle ...
DavidDunham's user avatar
0 votes
3 answers
53 views

xsel like a clipboard manager: keep clipboard content for future use

I'd like to run xsel as background process to keep clipboard content for future use. I run it in openbox startup script like that: xsel -b -k But when I select something with Ctrl-C and close ...
Anton Vakulenko's user avatar
3 votes
4 answers
347 views

Remove duplicates in file (without sorting!) leaving the _last_ of the occurences

Following https://www.baeldung.com/linux/history-remove-avoid-duplicates, I added clean_history() { awk '!a[$0]++' $HOME/.bash_history > $HOME/.bash_history.tmp && mv $HOME/....
Make42's user avatar
  • 699
0 votes
5 answers
110 views

To check whether first or last character of a string is x

I am trying to check whether the first or the last character of a string is x using zsh, and I get an error message instead: ./test.sh:2: bad substitution What is the problem here? string="2x3&...
jsx97's user avatar
  • 71
2 votes
1 answer
61 views

Grep return No such File, after comand substituion

I'm trying to use grep in a Bash script and assign the result to a variable: RESUlT=$(grep -R -I --exclude-dir=addons "^[^#]*print(" ) But it returns bash: Map/Places/place.gd:: No such ...
T.S's user avatar
  • 23
-1 votes
2 answers
179 views

Is it possible to translate bash to another human language like Arabic?

Bash commands are written in the Latin alphabet, is it possible to translate them to another language? In this case, Arabic. Arabic is written rtl and I remember I tried it using alias before when I ...
Abdelaziz Baheg's user avatar
0 votes
1 answer
82 views

How to make '.zshrc' to search for sourced files in the specific folder and not in the folder from which the terminal has been opened

macOS 14.5, Zsh 5.9. ls -A -- ~/: .zshrc system-wide-clipboard.zsh cat -- ~/.zshrc: autoload -Uz zmv alias zcp='zmv -C' alias zln='zmv -L' . ./system-wide-clipboard.zsh If I open the Terminal ...
jsx97's user avatar
  • 71
-1 votes
1 answer
56 views

Sourcing a shell script vs. Passing it as an argument to a shell interpreter [duplicate]

I'm new in shell scripting. As I discovered today, there are at least three ways to run a shell script: To execute it, using the absolute or a relative path: /folder1/folder2/script.sh ./script.sh ...
jsx97's user avatar
  • 71
-1 votes
2 answers
66 views

In bash/zsh, how to compare the metadata in two directories including . and excluding .. and the contents inside subdirectories?

Let's say that in a script, you have a directory $1 and its copy $2 and you'd like to compare the metadata (names, permissions, sizes, full modification dates, …) of the files and directories inside ...
AlMa1r's user avatar
  • 1
-2 votes
1 answer
61 views

regular single column data to multiple rows

source data KKK-SNMImsi: 444444 KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile KKK-SNMMmeAddress: TDSGSN01 KKK-SNMMsisdn: 44235682436 KKK-SNMLocationState: LOCATED KKK-SNMRoamingAllowed: FALSE ...
Peter Cherop's user avatar
1 vote
1 answer
60 views

Running a cronjob that requires setting of several environment variables in particular directory

I need to setup Cron Job to run regressions for which I usually follow below steps in terminal: cd path/to/regression_dir/ source setup.csh perl "regression_script.pl" The setup.csh files ...
Rutuja14's user avatar
1 vote
1 answer
87 views

incrementing file names in zsh

I am trying to write a script in zsh (Linux Mint 21.3 "Virginia") to move (or copy) a file from $source to $target with confusing results. I'm using yad file dialogs to select the files and ...
Terry 's user avatar
  • 35
0 votes
1 answer
39 views

Salesforce dataloader #!/bin/bash script errors mentions .zshrc

I'm trying to run a certain application (Salesforce dataloader v61) on MacOS. The entry point is a bash script: #!/bin/bash DL_INSTALL_ROOT="$(dirname "$(readlink -f "$0")")&...
Al Cher's user avatar
  • 101
11 votes
3 answers
2k views

UTF-8 characters in POSIX shell script *comments* - anything against it?

I would like to include a couple of non-ASCII characters in my POSIX shell script comments. Note this is in no way a duplicate of e.g. "Which character encodings are supported by posix?" as ...
Vlastimil Burián's user avatar
0 votes
0 answers
27 views

Why is the DWM status bar not getting mic info?

I don't really get why the mic status via icon isn't working on DWM: Status script #!/usr/bin/env sh # Log file path LOGFILE="$HOME/.cache/dwm_status.log" # Initialize printf "$$"...
DarKnightz's user avatar
0 votes
1 answer
43 views

Manipulating arguments with OPTIND, OPTARG, getopts, and shift correctly

My small POSIX shell scripts do not usually take any arguments, so this is kind of new to me... The minimal snippet would probably look like this: # default for hotkey variable on top of script is set ...
Vlastimil Burián's user avatar
-1 votes
1 answer
86 views

Bash deploy script only works the first time?

This script works perfectly the first time after starting it but when it's done it only continues to output zip_count: 0 afterwards. There seems to be some strange cache? I run the script inside Git ...
OZZIE's user avatar
  • 99
2 votes
1 answer
48 views

Is there a way to `exec` a pipeline or exit shell after launching a pipeline?

I'm writing a shell wrapper script that is supposed to act as a pager (receiving input on stdin and performing output on a tty). This wrapper prepares environment and command lines, then launches two ...
intelfx's user avatar
  • 5,466
1 vote
1 answer
88 views

Shell script to run command and show output in notification box

I have command line utility that generates text strings, by running a command within the directory: ./Utility -P it prints output on terminal. How to make a shell script showing the generated string ...
minto's user avatar
  • 525
-2 votes
1 answer
97 views

How to replace a parameter's value in json file with a value taken from a different text file

I have a a large number of JSON files on a Linux machine, where I need to change the value of a parameter with value taken from a different text file. E.g.: If the JSON file has values like: { "...
vishal's user avatar
  • 97
-1 votes
3 answers
63 views

Raspberry Pi 5 Unable to redirect script output to file

I'm using a Pi5 to run raspotify (a service that allows you to connect spotify from another device) it also starts a script "MyScript". I want to redirect the output from MyScript to a file ...
Martin Duckett's user avatar
0 votes
2 answers
76 views

Bash scripting: Last line - "exit" - necessary?

another basic, innocent question: When you make a bash script, you could close it with, you could type in as last line of the script, exit, echo "Hello world!" exit , is it advised, should ...
futurewave's user avatar
0 votes
1 answer
39 views

adding date and variable name to log file and generate a new one

I am trying to run a bash script on daily basis which generates a log file. #!/bin/bash exec 3>&1 4>&2 trap 'exec 2>&4 1>&3' 0 1 2 3 exec 1>logfile.output 2>&1 ( ...
vikrant rana's user avatar
0 votes
0 answers
14 views

How to assign stdout of subshells to variables in a platform agnostic way [duplicate]

I have discovered that on Sun 10, /bin/sh does not support $(...) syntax for variable assignments, with or without double quotes: -bash-3.2# uname -a SunOS unknown 5.10 Generic_147148-26 i86pc i386 ...
Shane Bishop's user avatar
5 votes
2 answers
726 views

Trapping SIGINT in a bash script does not work when that script is called as part of a pipeline

Consider the following minimal/arbitrary Bash script, which just slowly writes dots to stdout, until CTRLC is sent... ctrlc.sh #!/usr/bin/env bash declare -i have_ctrlc=0 function handler() { ...
jimbobmcgee's user avatar
-1 votes
1 answer
61 views

What is the effect of 'exec' shell built-in in a background pipeline?

Through iterative process I've created a following script that works exactly as intended - terminates VPN when the main process is interrupted and passes a password to stdin of openconnect. #!/bin/sh ...
Basilevs's user avatar
  • 200
12 votes
2 answers
4k views

Check if current user can run sudo without requiring a password

I want to check if the current user running a BASH shell script has access to passwordless sudo or not. If they don't, I'd rather have the script exit rather than prompting them for a password.
Jay Taylor's user avatar
2 votes
1 answer
281 views

Set default value of counter variable in bash script

Can you set the default value (parameter expansion) of a counting variable (shell aritmetic) so it doesn't have to be predefined in order to use it? Even if the resulting string is longer and more ...
Vita's user avatar
  • 311
0 votes
1 answer
48 views

how to use inotify to monitor a creation of a file and running it in the background

a beginner here. I am trying to write a script so that when a file (called "file1" for example) is created in a directory, I can see a notification and the inotifywait command I am using is ...
Ella Brudner's user avatar
0 votes
2 answers
94 views

How to edit selected words while preserving white spaces and newlines

By word I mean "a string of characters separated by any number of white space or newlines." Sample data on a rabbit's burrowing in the forest: a short tale Expected results On a Rabbit'...
Pound Hash's user avatar
0 votes
1 answer
114 views

ShellCheck does not detect error? How to fix my snippet?

I likely have syntax errors in the following (POSIX) shell snippet: #!/bin/sh if tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none; elif tput AF >/dev/null 2>&1;...
Vlastimil Burián's user avatar
0 votes
1 answer
55 views

What does a leading colon in a sh script line means? [duplicate]

Looking inside macOS Homebrew installed cask Emacs file named emacs-nw used to start Emacs in terminal mode, I see the following script (see below). What does the colon (':') at the start of the line ...
PRouleau's user avatar
  • 171
0 votes
1 answer
28 views

Crontab run after deleting a file

I have a script thar I want to be executed each first minute of each hour. Thus, i made a second file named crontab.sh: $ cat crontab.sh #!/bin/bash #cript path script_path="/mnt/lap_c/home/...
Dimitris Tsiaousidis's user avatar
0 votes
0 answers
39 views

SDDM PreSession

Need to run the script in SDDM after initializing the user session with sudo rights and use the $USER variable of the logged-in user in it. GDM has PreSession and PostLogin https://www.jirka.org/gdm-...
funny_rebbit's user avatar
0 votes
0 answers
16 views

How to force wifi detection in Fedora

I am using Fedora 39 and I am experiencing the following ennoyant bug. If I start my laptop without ethernet cable plugged in, it is all good my wifi connection is working fine. But if I was working ...
akasolace's user avatar
  • 193
0 votes
2 answers
76 views

How in convenient and flexible way to input time period for timer and convert it to seconds in Bash?

Like in sleep: sleep 1h 30m 50s. But ideally with even more flexibility like in time calculator with support time corrections with minus sign. Examples: time2seconds (t2s) 1h30m50s # basic case - ...
Anton Samokat's user avatar

1
2 3 4 5
330