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
33 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","...
0 votes
0 answers
31 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. I tried playing around with the bashrc file ...
0 votes
4 answers
121 views

How to make 'adb shell' to read /etc/profile or other configuration files?

I am working on an embedded Linux system (kernel-5.10.24), and it uses ash from busybox as /bin/sh. The system support login from serial console and adb shell from PC. Now I found the shell started ...
0 votes
0 answers
27 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.sh: echoSimultaneously() { parallel -j 0 echo ::: $string } run() { local IFS ...
0 votes
2 answers
74 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 ...
24 votes
1 answer
12k views

Run command 2 regardless of whether command 1 succeeds or not [duplicate]

I have cmd1 and cmd2. cmd1 && cmd2 will not run cmd2 if cmd1 fails. cmd1 || cmd2 will run cmd2 if cmd1 fails How do I run cmd2 regardless of whether cmd1 succeeds or not?
11 votes
1 answer
1k 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 ...
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 ...
0 votes
5 answers
2k views

List directories created in the last 3 days and display space usage

As part of disk clean-up, I am now required to delete all folders and its content created in the last 3 days (not the current business date): Example - today's date is 20191121, then: /opt/png/wsm/...
0 votes
0 answers
14 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 ...
12 votes
1 answer
73k views

Why is this error: "Interactive authentication required" popping up?

I don't get why this error pops up every time I want to run the systemctl commands. I know that I have to run it with sudo, which runs just fine, but I am curious, why is this happening? It didn't ...
-1 votes
2 answers
64 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'...
19 votes
2 answers
100k views

bash: cannot set terminal process group (-1): Inappropriate ioctl for device

Trying to execute the source command using "lfs" user on ubuntu 14.04 and getting this: root@linux:~/lfs# su lfs - -c "source ~/.bash_profile" bash: cannot set terminal process group (-1): ...
0 votes
1 answer
20 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 ...
12 votes
6 answers
42k views

Getting the first file in a directory in bash

How do you get the first file in a directory in bash? First being the what the shell glob finds first. My search for getting the first file in a directory in bash brought me to an old post with a ...
0 votes
0 answers
16 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 ...
2 votes
2 answers
5k views

Ping hosts based on filter and return dead or alive

I am trying to create a script that is capable of pinging multiple hosts from a text file in my directory. The hosts are with specific naming conventions and are grouped. E.g in the text fie 10.10.10....
17 votes
4 answers
28k views

find -exec in bash script with variable expansion

I'm trying to run a command similar to the one below in a bash script. It should search through all subfolders of $sourcedir and copy all files of a certain type to the root level of $targetdir. #!/...
0 votes
2 answers
53 views

How to get the cursor back on the last line of a file

I have a `text file with three numbers and each number separated by new line. -55 -56 -64 When I open the file I can see the cursor is on the fourth blank line. I want the cursor to stay on the last ...
74 votes
6 answers
46k views

nvm command not available in bash script

I am trying to build a script in in which nvm and eventually node will get installed. I have installed nvm with cURL. I see the modifications in the .profile or .bashrc file (both work) and when ...
0 votes
3 answers
87 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 &...
2 votes
1 answer
63 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) ...
0 votes
1 answer
4k views

ImportError: No module named pymol

I run a python script, but it returns this error. I am working on an environment and I believe that I have to install the pymol module. I am not familiar with these things and I have no idea how to ...
27 votes
10 answers
17k views

show only physical disks when using df and mount

When I use df or mount, I'm most of all interested in physical disk partitions. Nowadays the output of those commands is overwhelmed by temporary and virtual filesystems, cgroups and other things I am ...
-2 votes
2 answers
55 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 ...
4 votes
1 answer
2k views

Automating sshfs not working

I want to mount a remote directory and I want to automate this. So I write below script which not working properly. #!/usr/bin/expect -f spawn sshfs [email protected]:/home/user /mnt/remote expect ...
20 votes
6 answers
10k views

posix shell: print list of environment variable names (without values)

In a posix-compatible way that works with multiple implementations, how can I print the list of currently defined environment variable without their values? On some implementations (mksh, freebsd /...
46 votes
5 answers
112k views

Why doesn't my ~/.bash_profile work?

I'm using Linux Mint. My login shell (cat /etc/passwd | grep myUserName) is bash. After I start my graphical desktop environment and run a terminal emulator from it, I can see that .bash_profile is ...
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) > ~/...
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 │   └── ...
1 vote
1 answer
72 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 ...
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 ...
1 vote
2 answers
2k views

Self update bash script if there are any updates first then continue on, with Git

I'm trying to add the ability for my ArchLinux installer script to check if it's update-to-date based on rather it matches (or doesn't match) the version number that's on gitlab. The primary script ...
-2 votes
1 answer
75 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 ...
0 votes
1 answer
36 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 ...
7 votes
3 answers
16k views

How to control systemd service using screen?

I've set up a systemd service to run my Minecraft server. Now, I need it to repeat the start script when the server crashes. Here's my code so far: #!/bin/bash while true; do cd /home/mcserver/...
32 votes
6 answers
85k views

Can I access Nth line number of standard output?

Assuming a script that outputs a list of files: $> bash someScript.sh path/to/some/file path/to/the/file/i/want/to/work/with path/to/yet/another/file Now I want to have the second file-path as ...
-1 votes
2 answers
95 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?
-1 votes
0 answers
74 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 ...
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 ...
2 votes
2 answers
3k views

Shell script to check existence of multiple strings in a file

I have 3 strings A='apples' B='bananas' C='carrots' I want to see if all of these exist in the fruit.txt file. If I'm missing A then add A, B then add B, and so on. This is what I have now if grep -...
17 votes
1 answer
6k views

Turn on xtrace with environment variable

Bash has a sometimes-useful feature whereby if you turn on the "-x" option (I believe the symbolic name is xtrace), Bash outputs each line of script as it executes it. I know of two ways to enable ...
0 votes
2 answers
2k views

what are tty files for?

Can someone explain me what are the tty files? I can't understand that, using the command : echo 1 > /dev/tty prints to my current terminal the output: 1, but if i try to use echo 1 > /dev/tty0 ...
0 votes
1 answer
2k views

Udev rules, need to obtain path like /dev/sda

I try to get the path of the last connected disk via an environment variable, i.e. a path like /dev/sd*. The problem is that DEVNAME or DEVPATH does not provide the desired path. The goal is to make ...
15 votes
4 answers
15k views

Run a command using arguments that come from an array

Suppose I have a graphical program named app. Usage example: app -t 'first tab' -t 'second tab' opens two 'tabs' in that program. The question is: how can I execute the command (i.e. app) from within ...
0 votes
1 answer
37 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 ...
63 votes
9 answers
38k views

List all binaries from $PATH

Is there a one-liner that will list all executables from $PATH in Bash?
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 ...
3 votes
2 answers
843 views

Assign $@ to another variable in a shell function

I'm making an intelligent alias gc that can differentiate git commit/checkout. If gc is called without any arguments or with the -a, -m arguments, then git commit is run. Otherwise, git checkout is ...
0 votes
1 answer
20 views

Ubuntu/Orange Pi5 retrieve open tabs on Chromium (kiosk mode) via terminal - Powershell

I have a problem as of late where I am developing some PowerShell script to manage and update some digital displays. Please see below for my work in progress (By no means done). I am struggling to be ...

1
2 3 4 5
530