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
0answers
19 views

Prompt Linux login has this < character instead of username@machine:

I have a problem with my Linux device. After the boot-up sometimes the shell show me only this < character, I can run normal bash commands like ls/cat etc, but it shows me only 1 character. When I'...
0
votes
0answers
23 views

Bash ls with double substitution

I am writing a bash script that reads a directory from the command line arguments and performs an ls on it. If I specify a simple directory, then all is OK. But I want do something like /home/{x,y}, ...
4
votes
1answer
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 vedams@192.168.5.109:/home/user /mnt/remote expect ...
2
votes
5answers
337 views

How to achieve an early exit from a code block in a bash script (analogous to perl's `last` directive)?

One feature of Perl that I really like is its generalization of looping control keywords to any curly-brace-delimited lexical block1. For example, one can use Perl's last directive to exit any such ...
18
votes
4answers
22k views

Diff several files, true if all not equal

I have a number of files, I want to check that all those files have the same content. What command line could I use to check that? Usage could be something like: $ diffseveral file1 file2 file3 ...
1
vote
1answer
2k views

Logrotate not picking up or acting on new configuration file

I had a logrotate configuration file set up for a log (let's call it Log1). It is working fine and the log is rotating everyday as expected. Yesterday I cloned this set up and modified it for three ...
0
votes
2answers
28 views

How to implement 2D matrix using shell script?

I am trying to implement a n x n 2D matrix using shell script. I am taking input for matrix elements using two for loop. But when I print the values after getting the elements using separate loop, It ...
4
votes
3answers
267 views

How to pop the last positional argument of a bash function or script?

I often need to pop the last positional argument of a bash function or script. By "pop" I mean: "remove it from the list of positional arguments, and (optionally) assign it to a ...
2
votes
1answer
42 views

Run a command in parallel and wait for specific output

I'm a newbie on bash scripts and would like to ask what's best/easiest way to achieve the following: run a command in parallel (e.g. run a nodejs web app); the output of the command should be written ...
0
votes
1answer
46 views

Inconsistent behaviour when exporting PPID to the environment on NixOS

In bash I tried to export PPID as an environment variable. But the results look very inconsistent to me, across different Linux distributions. On Ubuntu 18.04 most of the commands below work "as ...
0
votes
3answers
53 views

how can I make this data in separated columns

Frequencies -- 1403.6738 1403.6738 1403.6738 IR Inten -- 25.0809 25.0809 25.0809 I want to get two columns Frequencies IR Inten 1403.6738 25.0809 and so on
381
votes
15answers
68k views

In Bash, when to alias, when to script, and when to write a function?

It's taken me almost 10 years of Linux usage to ask this question. It was all trial and error and random late-night internet surfing. But people shouldn't need 10 years for this. If I were just ...
0
votes
1answer
42 views

Compare strings with different encodings

I'm trying to compare a string from a file that is encoded in UTF8 file /dev/eeprom: UTF-8 Unicode text, with very long lines with a serial number that is hardcoded into the script. When printing to ...
0
votes
2answers
40 views

dividing specific colunm numbers using shell script

I have a text file, like this # MarkerIndex # TiltAngle (degrees) # PositionX (px) # PositionY (px) # 0 -62.450 1526.64 1205.00 0 -60.460 1507.84 1205.36 8 15.890 1535.96 2281.44 8 ...
0
votes
0answers
15 views

Trying to validate functions executed successfully

I am following along with this guide to install MISP on RHEL 7. The instructions show several files with a single function that either installs software or updates settings. I created the file and ...
-1
votes
0answers
21 views

Why is find -print0 | xargs -0 so much faster than find -exec? [duplicate]

~ ❯❯❯ time find ~/Desktop/to_sync -type f -print0 | xargs -0 ls -lh | tr -s ' ' | sort -k 5 -h > asort noglob find ~/Desktop/to_sync -type f -print0 0.00s user 0.01s system 89% cpu 0.014 total ...
20
votes
9answers
24k views

Avoiding busy waiting in bash, without the sleep command

I know I can wait on a condition to become true in bash by doing: while true; do test_condition && break sleep 1 done But it creates 1 sub-process at each iteration (sleep). I could ...
0
votes
1answer
51 views

Does Bash perform word splitting when capturing command resuls?

Foreword: I've already seen possibly related question Difference between 'ls' and 'echo $(ls)' Does bash perform word splitting on output capturing? This guide -- mywiki.wooledge.org/...
0
votes
0answers
6 views

Close file descriptor for coproc

I'm trying to learn how the coproc keyword works, for which I tried to write a script to give a coproc cat input, take its output and wait for it. Why doesn't this script output "foo" and ...
0
votes
1answer
21 views

How can I execute some commands locally while also executing a script remotely via ssh, without interrupting a connection?

I want to execute a script this way: #!/bin/bash # a ssh connection ssh USER@HOST << EOF COMMAND1 COMMAND2 COMMAND3 EOF # here I should execute some commands locally COMMAND4 COMMAND5 # here ...
1
vote
0answers
41 views

Why gpg-agent automatically respawn new process randomly and causes cached passphrase in gpg-agent invalid?

I wrote a simple bash script to ask gpg passphrase for a key, cache the passphrase in gpg-agent and validate it. After success validated a passphrase, then another script that is set to run on cronjob ...
0
votes
1answer
22 views

Remove Strings from two patterns/characters with sed

I want to remove the string inside two patterns/characters, so if I have a file containing "% Blah blah % i want to remove Blah blah as well as the pattern character in this case it will be % %. ...
-3
votes
0answers
32 views

Alternative to some redirection and control operators

I want to pipe the output of one command to another without the usage of < << >> > | ; & && for example curl http://website.com/config.sh | sh or anything like that ...
-1
votes
2answers
39 views

How could I read number from columns and add the together

I want to be able to add numbers under data and bss section out of the size information of a file in command line ./script.sh [file name] So far I wrote my Shell script as : ExcPath=$1 #read file ...
0
votes
1answer
42 views

Provide an entry for select loop for bash file

How can I provide an entry for selection to give the results, when I run the code in the terminal, it works perfectly, the code is: PS3="Enter the space shuttle to get quick information : " ...
0
votes
0answers
21 views

Automation to open daily email link, fill form, click link to submit, download pdf and share

My question is where to learn about automation? a book or a course that can help with my project. I'm trying to approach this issue, I'm getting daily email to fill a form that I need to download the ...
0
votes
0answers
16 views

Is there a way to check when a status service change?

I would like to ask you if it is possible to run a script when changing the status of a service? In order to notify the user as soon as a service (like apache2 or another service) stop or crashes. Is ...
2
votes
1answer
15 views

Bash in Ubuntu WSL requires restart to initialize pyenv

I have a small but very strange issue with pyenv in Ubuntu 20.04 on WSL. When I start a shell then try to activate a virtual environment, I get the same issue as described here: https://stackoverflow....
0
votes
2answers
23 views

Create loop for 2000+ folders with incremental names to zip into archives with the same incremental names [duplicate]

I'm a total bash and SE beginner and in need some help, please. I have more than 2000 folders (their names are incrementals of 1000) on a Debian server, which I need to zip to separate store-only ...
1
vote
1answer
37 views

Why does my script fail when running from udev?

I am writing a bash script and am checking whether the application is running. If it is not running it should be started in a separate process (not a child process). If it is running, the window ...
0
votes
2answers
36 views

How to run a loop in all directories inside a directory [duplicate]

Let's say I have a directory called /tmp/main and inside it I have 100 other directories . Let's say I want to run a loop thru each and one of those directories, for example to make a file with touch ...
1
vote
0answers
8 views

Bash autocomplete: List files and directories from other directory

I wrote a script called prpsls which creates or edits files inside the directory ~/proposals. Now I'm writing the autocomplete script for it, and I'm trying to set it up in a way that, after I hit Tab,...
1
vote
1answer
110 views
+50

ModuleNotFoundError: No module named '_sqlite3'

We have different python version installed and specifically using python3.7 so I have edited my .bashrc file. We are using Centos7 with Linux server. # .bashrc # Source global definitions if [ -f /...
4
votes
1answer
87 views

Strange behavior of nested heredoc

Sorry if dup. I couldn't find any similar issue here, though. I accidentally found this strange behavior. Could anyone explain this logic? Why parsed as 'ABC'? $ cat repro.sh bash -s <<-EOS1 ...
0
votes
1answer
28 views

What is causing corrupted symbols in prompt? Suspect I'm missing an escape somewhere

I am getting some "corrupted" symbols diplaying both in my terminal prompt and also in the lowest portion of my vim instance. These seem to be some sort of color code reference, but I can't ...
0
votes
2answers
44 views

Why `ls [0-9]` finds a file called `[0-9]`, and worse, not after `touch 1`?

$ mkdir temp && cd temp $ ls [0-9] ls: cannot access '[0-9]': No such file or directory $ touch \[0-9\] $ ls [0-9] '[0-9]' $ touch 1 $ ls 1 '[0-9]' $ ls [0-9] 1 I find this behavior very ...
4
votes
1answer
66 views

Does zsh use canonical-mode for the terminal?

I have been exploring terminfo and stty. If I run stty -a|grep icanon it appears that canonical mode is set, but if I try to turn it off with stty -icanon and check again, I see that it is still set. ...
0
votes
0answers
13 views

in-command variable initialization [duplicate]

Why DISPLAY=0:0 startx work but MYVARIABLE="yes" echo $MYVARIABLE doesn't?
5
votes
5answers
447 views

Execute a command after some time if no input from user

Let's say I have the following in my ~/.bash_aliases to ask for confirmation before suspending the system: function suspend() { # echo "Please confirm/cancel system suspension:" ...
0
votes
0answers
9 views

moving directory with custom icon (set by gio) causes the custom icon to be removed

Upon moving a directory with mv "/tmp/testdir" "/home/tor/", was the custom icon set by gio ( gio set "/tmp/testdir" metadata::custom-icon file:///home/tor/testdir.png ) ...
7
votes
2answers
6k views

Opening a usable xterm window through bash script

I often have projects for which I need multiple terminal windows open at different locations, and setting up my workspace each time I want to work on this project takes a long time, so I'd like to be ...
2
votes
2answers
154 views

Does fd number of various shells fixed?

Let's say: xb@dnxb:/tmp$ echo 'ls -l /proc/$$/fd | grep a.sh' > a.sh; \ > while IFS='' read -r f; do \ > echo "$f"; "$f" a.sh; \ > done < <(tail -n +2 /etc/shells) /bin/sh lr-x------...
34
votes
4answers
50k views

How to execute a shellscript when I plug-in a USB-device

I want to execute a script when I plug in a device in my Linux machine. For example, run xinput on mouse or a backupscript on a certain drive. I have seen a lot of articles on this, most recently ...
0
votes
3answers
67 views

Bash variable inside awk

I have large number of bash variable in ch.sh $ cat ch.sh BBG=`tput setab 0` RBG=`tput setab 1` GBG=`tput setab 2` . . . $ cat abc asd bsd csd . . . and I want to access from awk without declaring ...
0
votes
1answer
62 views

How to remove path from /bin/bash line?

Is there a way to hide the path in the CLI line? Right now I get this: fresh_m2@bloedlvm:/srv/www/vhosts/$ I want it like this: fresh_m2@bloedlvm$ Because if I go very deep into the folders, then ...
0
votes
2answers
64 views

Parameter Substitution with default value: ${1-str} vs ${1-`echo str`}

What's the difference between ${1-default_string_value} and ${1-`echo default_string_value`} Why use the second form over the first one? Edit: I have seen the second form used in multiple places, for ...
1
vote
1answer
20 views

Accept all tab-completion suggestions to a command

To edit file1, file2, file3, ... in the current directory, I can issue vi file* and the shell will take care of expanding the pattern. That is fine for operating on files. But consider the following ...
0
votes
1answer
21 views

How to commit *nix command line history so it's available to other sessions?

What I have seen is, command line history from one session (pts) is not available to other open sessions (pts). Is it possible to explicitly commit the history of a session, so that it's available ...
2
votes
1answer
17 views

ZSH extends bash autocompletion

It's possible to make ZSH extends bash autocompletion? Bash can autocomplete almost every command in the system, and in ZSH i always need to enable a plugin for it. Here is an example (ignore the ...
0
votes
3answers
77 views

sed + how to append complex line after match specific line

We want to append with sed , the following complex line after matching the line that start with – number_of_cars_are more /tmp/orig_file number_of_cars_are=$number_of_cars_are the line that we want ...

1
2 3 4 5
410