Questions tagged [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.

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

Bash completion doesn't work with remaped tab key?

I just change my os to Nixos with Gnome 42.2 as DE. I changed my fn key to tab using this xmodmap command: xmodmap -e "keycode 151 = Tab" It allows me to scroll through input form on ...
  • 1
0 votes
1 answer
5 views

startProcess: posix_spawnp: does not exist (No such file or directory)

I have an interesting case where I'm getting the below error when running a bash program but only when it's run via a systemd unit (running within Nixos). telegram: startProcess: posix_spawnp: does ...
-1 votes
1 answer
23 views

add a new line after a specific string in a file? [duplicate]

Right now I'm using echo sed '/\Random/a \ newly added line' info.txt to append some text to a file but I also need to add text below a certain string let's say random, I know it is possible with ...
1 vote
1 answer
11 views

Parameter Substitution inside Indirect expansion

I want to achieve the Parameter Substitution inside Indirect expansion. But I am not able to achieve it with a single command I get the Bad Substitution, let me know if there's a clever way of solving ...
1 vote
0 answers
10 views

Runnig python window app on linux (Fedora) without gdm

I have a small project, the project is running python (windows application) as below.On linux Fedora without using gdm,Gdm must be disabled. Any Idea please? What library I have to download ? # ...
1 vote
1 answer
20 views

How to make a script to rename images and videos with the date of modification?

I have a gallery folder with images and videos in it named in unwanted format. I want to make a script that scans through each file in that directory and when it finds an image or a video to rename it ...
1 vote
1 answer
24 views

Fail handling SIGINT in hierarchical process execution

I have the following process execution structure: script0.sh script1.sh script2.sh script3.sh Meaning: script0.sh executes script1.sh. script1.sh executes script2.sh and script3....
  • 2,203
0 votes
0 answers
20 views

rsync: No such file or directory (2)

I get this despite that remindfox.ics is copied. Any fix? rsync: link_stat "/home/andy/.mozilla/seamonkey/dsgt0f2o.default/reminderfox.ics" failed: No such file or directory (2) rsync error: ...
  • 103
-2 votes
2 answers
25 views

am not sure how to write on other file

hi i have this script called script.sh have 2 variable #! /bin/bash read -p " name " name read -p " last " last ( here am not sure what to do but if possible to open file name....
0 votes
0 answers
25 views

Why does this error message open with a ` char, but close with a ' char? [duplicate]

GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin21) In a new bash shell, I tried to declare a function but saw the following error: syntax error near unexpected token `str' I'm curious why ...
3 votes
2 answers
115 views

Bash Parameter Expansion - Get Variables with a Prefix while Escaping Hyphen

EDIT: I realized I was mistaken about a central assumption in this post: The ${!prefix@} syntax isn't able to get function names, but only variables. Therefore, there is no way to get ${!prefix@} to ...
  • 133
0 votes
3 answers
62 views

Need help understanding this bit of bash code: "${i%.*}_MYSUFFIX.${i##*.}"

for i in *.shp; do ; mv -v "${i}" "${i%.*}_MYSUFFIX.${i##*.}" ; done This loop inserts_MYSUFFIX before file extension in my directory...great stuff but I am struggling to ...
  • 1
0 votes
1 answer
11 views

Bash script to ping remote machine hanging

I have a bash functions file named ping that has a single function: #!/usr/bin/env bash ping() { ping -c 1 $i.local } This file is loaded by another bash file named pinger and attempts to use the ...
  • 103
0 votes
1 answer
36 views

Add heredoc (<<) to end of alias within function call

I have an alias which is my psql connection string for a database, let's say the alias is this: alias GQQ='psql "host=$host user=$redshift_uname dbname=$redshift_dbname port=$port pass word=$...
0 votes
1 answer
43 views

How to run command when user push ctrl+c?

User selects any text and push ctrl+c. How to autorun command after this action? I need solutions for: How to get notification/check about the state of the clipboard After notification/check will ...
2 votes
2 answers
86 views

Is there a pipeless, simple one liner to execute a command for each line in a file?

For example, # a demonstration of the functionality cat dependencies | xargs -n 1 pip install -U # expressed as a non-simple, pipeless one liner awk '{system("pip install -U $0")}' ...
  • 715
2 votes
1 answer
20 views

How to remove color from print to make it suitable for piping

I'm piping some Unix commands with my own scripts. The problem is that in my scripts, I'm using colors. Like for example: yellow=`tput setaf 3` reset=`tput sgr0` function Warning() { echo "${...
1 vote
1 answer
44 views

Bash Function Grep Mod

TL:DR How do I add a grep to a bash function while allowing a variable number of optional inputs? I find that in repeated grepping of large outputs, I end up clogging the terminal with data. ...
1 vote
1 answer
55 views

Bash variable truncated when passed into ffmpeg

I have an album of 11 .flac audio files. (edit: since this issue has been resolved, it's now clear that the precise names and content of the files are irrelevant, so I've renamed them): > find . -...
0 votes
1 answer
36 views

Trap Ctrl C in script

I need to figure out how to trap Ctrl C, so that if I want to end the script early, it can re-enable the suspend and hibernation modes. I looked at other discussions of trapping Ctrl C, but found none ...
  • 103
1 vote
1 answer
19 views

Makefile: how to assign object to variable and iterate on object of array

Makefile: QUERY := "securityresources | where type == 'microsoft.security/assessments' | summarize by assessmentKey=name | join kind=inner ( securityresources | where type == 'microsoft.security/...
0 votes
1 answer
20 views

Why do I get syntax error but in same cmd if I remove else block it does not give syntax error?

M_ID,M_NAME,DEPT_ID,START_DATE,END_DATE,Salary M001,Richa,D001,27-Jan-07,27-Feb-07,150000 M002,Nitin,D002,16-Feb-07,16-May-07,40000 M003,AJIT,D003,8-Mar-07,8-Sep-07,70000 M004,SHARVARI,D004,28-Mar-...
  • 3
4 votes
1 answer
171 views

Pipe stdout while script has read command

I have a small script (called stc) to create a SecureToken with stoken #!/bin/bash # Read Password read -p "Password " -s PASS TOKEN=$(stoken --stdin <<< "$PASS") xclip -...
  • 153
4 votes
2 answers
170 views

How to properly use command substitution as argument of a command with a space in file list?

Let's say I have a file called FILES with the content : /path/to/something /path/to/something/else /path/to/something/else/with/a space /path/to/something/else/again If I try to use command ...
  • 1,782
1 vote
2 answers
17 views

Save a variable to environment till it is not erased

I am new to bash scripting, so if I ask anything stupid sorry for it xD I'm making a script which run come cli commands everyday. The output which I get from the cli command is a ID which I have to ...
  • 139
1 vote
0 answers
28 views

Unable to replace specific line from file using sed

I have around 100 scripts in as many folders, all of which have a specific value for my variable config_list. I want to edit its 14th line from for i in 10-35-5 8-35-7 to for i in $config_list where, ...
1 vote
0 answers
23 views

Permission Error

I have installed bash shell in windows 10 to run linux commands. I am trying to execute a script which gives error "You do not have permission to edit". I have executed command "chmod ...
1 vote
1 answer
19 views

How do we write only fail jobs in a log when we use GNU parallel

parallel --joblog /tmp/log exit ::: 1 2 3 0 cat /tmp/log Ηow can Ι use a filter to write only failed job in my load when using GNU parallel or is there a way to get only failed jobs from the above ...
0 votes
1 answer
31 views

Prevent starting a program if it is already running and has opened a particular file

I need to restrict a a_command myfile couple to only one instance. In my particular case I run qemu-system-x86_64 [options] -drive file=myfile.img,format=raw The script should check whether both ...
1 vote
1 answer
33 views

Determining name of the variable passed to function

If I pass variable as a positional argument to a function, is it possible to determine the name of the variable used from inside the function, or I can only access its value? I have a function envir-...
  • 111
13 votes
2 answers
2k views

Why is the -e option not in the bash command manual?

I'm a little confused about the missing -e option from the bash manual. man bash But it is working with a script shebang like : #!/bin/bash -e and of course it is defined in help set. Why isn't it ...
  • 1,782
0 votes
1 answer
34 views

Unsetting an exported environment variable

I am using export to set an environment variable. export OPCON_VERBOS=${vb} How can I then unset it later so that it stops being define anymore?
  • 111
2 votes
1 answer
23 views

Can updatedb keep localpaths for removable drives that aren't plugged in?

I run updatedb like this: updatedb --localpaths="/a /b" /a is a removable drive. /b is the local hard drive. Although /a's not always accessible to me, I frequently want to run locate to ...
1 vote
1 answer
30 views

Rename files and append parent directory name to filenames?

I am trying to rename files and append their parent directory name to them (and move them to a new folder named Photos). I've been trying to do this with rename and mmv, but I am having difficulties ...
  • 37
0 votes
0 answers
21 views

Securely run shell command using php from another server

I've got Server A where the main website is hosted. I've got a panel there that I'd like to safely run a shell command on Server B every time a new user joins in. I will basically create a new user on ...
  • 1
0 votes
0 answers
32 views

Ubuntu on Windows: why is cd /mnt/c/Users/username/Desktop not working?

I'm running Ubuntu 20.04 on Windows 10. I have been able to access the directories in my desktop directly by using the cd /mnt/c/Users/username/Desktop command until yesterday, but today I tried ...
  • 101
0 votes
0 answers
8 views

how to force runuser to initiate an interactive shell the same way `bash -i` is used?

I need to run the following command as mruser as root systemctl --user status myservice To do this I use runuser runuser -l mruser -c "systemctl --user status myservice" This works perfectly ...
  • 428
0 votes
1 answer
32 views

Environment variable and function argument

I have a collection of bash functions that include a verbosity level option. According to the set value, different levels of outputs are generated. The verbosity is local to each function. But I ...
  • 111
0 votes
1 answer
21 views

Cross-reference if a match occurs between strings across files

I need help to cross reference two files. file1 Aplastodiscus_albofrenatus_CFBH5051 Aplastodiscus_albosignatus_MZUSPfield1451 Aplastodiscus_arildae_USNM303022 Aplastodiscus_cavicola_MNRJ63689 ...
0 votes
1 answer
39 views

Prevent splitting command line argument at spaces when running in bash script [duplicate]

I'm trying to run a command in a bash variable, like this: cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234" $cmd It looks like it is splitting the command line ...
1 vote
1 answer
26 views

How to split the content of a folder into subfolders

I would like to know if there is an easy way to automatically (programmatically, within a bash script) to split the content of a folder into subfolders with the parent folder. I have a folder let's ...
3 votes
3 answers
409 views

Testing for Zero or Positive Whole Number

How can I test whether a number in a bash script is 0 (zero) or a positive whole number?
  • 111
-1 votes
3 answers
37 views

Searching filename for certain string and saving it to a variable in a shell script

Let's say I have files with a very specific naming scheme. For instance, maybe I have a file named x=1,y=15,z=63.txt, and I've saved this filename to the variable file. I want to search the variable ...
  • 11
0 votes
0 answers
40 views

Is there an optimized solution for tcpdump pulling a specific IP?

I made a script that runs tcpdump in the background: nohup tcpdump -i $INTERFACENAME dst $IPC >> text.txt And I made another script that pulls any IP address other than $IP from text.txt, but ...
2 votes
3 answers
536 views

Remove duplicated word from a file

I have a text file of format something like path1/path2/path3a 34474538656 path1/path2/path3a 8115147679 path1/path2/path3b 2266371027 path1/path2/path3b 3860823 path1/path2/path3b 554247 And this ...
1 vote
2 answers
62 views

Is this bash variable a valid IP v4 or 6 address?

I have a bash (v5.2 from latest Debian testing/bookworm apt) variable called TARGET. How can I check if the contents is a valid IPv4 or IPv6 address, rather than something like ERROR?
  • 1,096
5 votes
3 answers
471 views

Add an item to a list of piped items

I need to add items to a list of items. I am not sure if these are the correct terms. Example: Suppose I am inside a directory with 2 files, "a" and "b". If I pipe ls to less my ...
  • 297
0 votes
0 answers
28 views

Variables that keep their value for different xterm instances

I would like to have a variable that determines the verbosity of the output from various bash functions. But I want that the variable settings can be used also be subsequent xterms. There is the ...
  • 111
3 votes
2 answers
297 views

Grouping of bash conditionals

I have the following bash condition test which I need to change. if (( exec_rc == 1 )) && [ -z "$keymap_actm" ] && [ -n "$modmap_actm" ]; then (( exec_rc == 1 )) ...
  • 111
0 votes
0 answers
55 views

Welcome message in the terminal

I'm trying to create a script that shows a welcome message when the root user enters the terminal. My current problem is that the welcome message also gets shown if a normal user starts the terminal......

1
2 3 4 5
482