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
2 votes
2 answers
178 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
0 votes
0 answers
23 views

Terminal does not use .bashrc variables, but recognized them [duplicate]

I have installed the latest Pop!_OS version on my new computer and wanted to set the following environment variables: CC=/usr/bin/clang CXX=/usr/bin/clang++ CMAKE_GENERATOR=Ninja Instead of typing ...
mxHuber's user avatar
-1 votes
1 answer
67 views

How can I ensure that I always run something when a non-interactive shell is launched?

Let's say I have a script: #!/bin/bash whoami I would like to have it so that when I execute this script, foo is always printed before its execution. In fact, I would want foo to be printed before ...
Foo's user avatar
  • 230
-1 votes
0 answers
35 views

Bash ignores ' and ' when assigns data to variable [duplicate]

export Test='[{"order":1,"version":8,"layer_id":7,"source":"role","path":"g.base","crc":"c2894989","...
Joe Mendel's user avatar
0 votes
2 answers
31 views

linux find and rename items with backslash not working as expected

I have tried a couple of approaches to find and rename some files that hold a backslash (mind you these files generated from a web app do not have the quoets) in a directory. I've tried with find and ...
gstlouis's user avatar
0 votes
0 answers
15 views

Launching via Plasma shortcut removes ssh-agent's environment variables

Running Plasma 5.27.10 on Debian testing/trixie. An ssh-agent is launched via user service /usr/lib/systemd/user/ssh-agent.service and its socket is exposed in my session's environment variables. All ...
Tarmo's user avatar
  • 101
-1 votes
2 answers
74 views

How to get common lines for two variables with multiline text?

I have line-by-line list of domains I got by for domain in $(nginx -qT | grep -E "^[[:space:]]*server_name" | grep -Ev "^[[:space:]]*#" | sed 's/^[ \t]*//' | sed 's/server_name //g'...
palmasd1's user avatar
  • 119
0 votes
1 answer
22 views

GNU parallel: how to call exported bash function with empty string argument?

Scenario: $ process(){ echo "[$1] [$2] [$3]" ; } ; export -f process $ process "x" "" "a.txt" [x] [] [a.txt] Here we see that the 2nd argument is empty string ...
pmor's user avatar
  • 579
0 votes
0 answers
19 views

How to set ACL permissions for SSH_AUTH_SOCK in a RemoteCommand?

I'm trying to forward my SSH agent and then grant permissions to the SSH_AUTH socket. The permissions are for another user on the remote host. My ssh config: Host myhost Hostname 1.1.1.1 ...
dimid's user avatar
  • 627
1 vote
2 answers
89 views

Use shell script to select a specific pdf with unique filename format and recent creation-date?

I am needing some help with a script. I'm currently trying to select PDF file that meets a specific requirement in the file name in order to move it to a different location. The filename format I'm ...
Brad Barnes's user avatar
-1 votes
1 answer
39 views

How To Have GNU Parallel Command Pick up Variables, Defined Outside of It?

My actual case is more complicated, but this is the problem I'm having. Simplified Example echoSimultaneously.bash: echoSimultaneously() { parallel -j 0 echo ::: $string } run() { local IFS ...
Nickotine's user avatar
  • 463
2 votes
1 answer
67 views

AIX - BASH REGEX INTO IF STATEMENTS = Segmentation fault (coredump)

Hello everyone and thanks for your support! I'm facing a problem while using REGEX inside a bash script through =~ operand. Environment: GNU bash, version 4.1.7(1)-release (powerpc-ibm-aix5.1.0.0) ...
omar.c's user avatar
  • 23
-2 votes
3 answers
69 views

sed inline not working

the problem is that I cannot put the complete command on a line with SED, I had already done it but with those file it does not work: my exemple : <file>Documents/time/text1</file> //2X ...
Allan Tori's user avatar
2 votes
4 answers
120 views

SED command to delete a forward slash "/" between 2 tags

I am using Linux, and I want to use sed to delete a forward slash (/) between 2 tags. From this: <file>/text</file> <file>/text2</file <file>/text</file>.. to this &...
Allan Tori's user avatar
0 votes
0 answers
18 views

bash autocompletion filetype filter bypass

How to ignore bash autocompletion's file filtering when it's broken? For example, I want to auto complete a iso file for bsdtar, but my distro didn't include that extension. Pressing tab just feel ...
gcb's user avatar
  • 360
0 votes
1 answer
37 views

Find all the folders that are concealed using 'chflags'

I have concealed some folders on my laptop using chflags: chflags hidden hide-me And I don't remember where exaclty these folders are located. How is it possible to find all of them? (Probably by ...
jsx97's user avatar
  • 107
1 vote
1 answer
78 views

Popup cannot be interacted with: "Daemons using outdated libraries" "Which services should be restarted?"

The pop-up "Daemons using outdated libraries" "Which services should be restarted?" breaks my scripts as it cannot be interacted with, requiring me to interrupt. It happens when I ...
BigMistake'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
-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
-2 votes
1 answer
76 views

Download File Which has the latest Time Stamp From Website [closed]

Website is like this Can't add the actual site as it's from work. These files don't have version numbers, but have different names. No latest file link either, it's a very minimal website. You can ...
Nickotine's user avatar
  • 463
-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
1 answer
38 views

bash DEBUG trap is not inherited by subshell despite set -T

I'm using: $ bash --version GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) Given: #!/bin/bash validate() { if [[ "$BASH_COMMAND" == whoami ]]; then echo "whoami ...
Foo's user avatar
  • 230
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
3 votes
1 answer
177 views

Prevent command from running in zsh

In bash I can do: #!/bin/bash validate() { if [[ "$BASH_COMMAND" == whoami ]]; then return 1 else return 0 fi } set -T trap 'validate' DEBUG shopt -s extdebug so ...
Foo's user avatar
  • 230
0 votes
1 answer
25 views

Difference between cp and cp -rf on a Mac

Could anybody explain is there any difference between cp some-file.txt some-folder and cp -rf some-file.txt some-folder on a Mac? I was told that cp -rf forces cp to overwrite existing files, but it ...
jsx97's user avatar
  • 107
0 votes
0 answers
45 views

cron task can't read from a network drive (wsl)

I want to define a simple cron task that gets list of files and directories available in a specified folder and saves it to a file. Here's the output of crontab -l 30 * * * * ls /mnt/q > /tmp/test....
LA.27's user avatar
  • 113
-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
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
0 votes
0 answers
41 views

Thunar warning content type loading failed

I'm running a bash script that collates and organises files before turning it into a zip. When I run the script, multiple Thunar 'warnings' and 'critials' pop that I have a hard time figuring out what ...
LifeIsGood's user avatar
15 votes
4 answers
4k views

How do I read the last lines of a huge log file?

I have a log of 55GB in size. I tried: cat logfile.log | tail But this approach takes a lot of time. Is there any way to read huge files faster or any other approach?
Yi Qiang Ji's user avatar
0 votes
2 answers
38 views

I want to "Autocomplete" sub and sub/sub directories rooted in a fixed directory

I have some directories with music files $ tree -d ~/Music/ /home/boffi/Music/ ├── Aldous_Harding │   ├── Aldous_Harding │   ├── Designer │   ├── Party │   └── Warm_Chris ├── Madness │   └── ...
gboffi's user avatar
  • 1,372
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
0 answers
22 views

Exclude a filename suffix from glob match [duplicate]

I've read the documentation but couldn't find the answer to what I wanted to achieve. I have the following files: $ ls a a. a.b ab a.c ac I have the extglob shell option enabled. I want to ...
k314159's user avatar
  • 403
0 votes
1 answer
46 views

How can I start a NPM app from a desktop shortcut?

I have created a desktop shortcut for a npm application called TMXEditor, but it doesn't work. I can launch the app if I do cd /home/souto/Apps/maxprograms/TMXEditor && npm start on a terminal....
msoutopico's user avatar
1 vote
1 answer
64 views

How to display text for non-interactive login shell

What I need: I am trying to change /etc/bashrc in such a way that shell could display specific text when the following ssh command is entered ssh user@ip "whoami" But I don't understand ...
Judith5230's user avatar
-1 votes
0 answers
43 views

Alias to process groups my system has and return them

I'm trying to get this alias right, but it won't sort properly. Can anyone help me out? alias groupls="cut -d: -f1,4 /etc/group | sed -e 's/\n/ /g' -e 's/:$//g' -- | tr '\n' ' ' | sort | uniq&...
Aleph's user avatar
  • 1
0 votes
1 answer
60 views

Symbolic link to application - working directory

Lets say i have a bash script in a folder called Programming, which reads data from files in a subfolder named data. The paths in the script to the files are all relative to this "Programming&...
Schmaehgrunza's user avatar
1 vote
2 answers
47 views

Which -newerXY option finds all files that are accessed after creating or modifying another file?

This question relates to Xubuntu 22.04 if that matters. Probably it is a general Unix question, however. In a shell script, I first want to create a reference file, e.g. by echo $(date) > ~/...
Adalbert Hanßen's user avatar
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
48 views

LINENO and BASH_LINENO

So I'm not sure why this is.. I know ${LINENO} normally contains the line in the script, and BASH_LINENO goes based on input from BASH_SOURCE as an array $ (echo hi;declare -p LINENO BASH_LINENO;echo ...
linuxgeek'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
4 votes
1 answer
505 views

Why does filtering a bash array using negative pattern matching and parameter expansion have unexpected results?

I'm doing a small-ish pure bash script to roll dice; as such I'm having to manipulate arrays. I want to do something akin to a filter operation in other languages: extract some of the things in the ...
CyberFoxar's user avatar
5 votes
2 answers
177 views

Is the output of `declare -p <variable>` in bash guaranteed to be reusable as shell input?

This is specifically about bash's declare - the general case is pretty exhaustively dealt with in this answer (which mentions "the typeset/declare/export -p output of ksh93, mksh, zsh" but ...
muru's user avatar
  • 72.3k
5 votes
3 answers
472 views

awk: sort by first column then second; output unique 1st column once but all 2nd column

I have a two-column file that you can create as follows cat > twocol << EOF 007 03 001 03 003 01 137 12 001 11 002 01 002 02 002 03 001 02 002 04 137 94 010 21 001 01 EOF The resultant file, ...
bballdave025's user avatar
1 vote
2 answers
90 views

Hide single argument from bash history

Is there a way to hide a single argument passed into the terminal, but still pass the argument to the command? This question addresses the problem of passing a plain-text password through the shell. ...
Jesse's user avatar
  • 345
1 vote
1 answer
53 views

Have lsof take action if a process has a file open — and, ideally, do so repeatedly

Per the EXAMPLES section in the lsof(8) man page on manpages.ubuntu.com, I should be able to run a command/take action if a process has a file open: To take action only if a process has /u/abe/foo ...
Bink's user avatar
  • 297
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
1 answer
40 views

inotifywait not listening to DELETE event

I'm using the following bash script to test inotifywait. while true; do inotifywait -r -e modify,create,delete "$DIRECTORY_TO_WATCH" done inotifywait is listening to created files: /...
wyc's user avatar
  • 133
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

1
2 3 4 5
518