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.

learn more… | top users | synonyms

1
vote
2answers
38 views

Scope of Local Variables in Shell Functions

After reading 24.2. Local Variables, I thought that declaring a variable var with the keyword local meant that var's value was only accessible within the block of code delimited by the curly braces of ...
0
votes
0answers
48 views

How can I find where tmux is installed on my computer? I would like it to autostart when bash starts

I know that this exists. But it isn't working, and when I try to find tmux in the "bin" directories of my computer, it doesn't find it. How is it working when I enter tmux into terminal then? ...
1
vote
0answers
36 views

compare variable value with part of IP [duplicate]

I have several IP addresses that I want to list it based on internal or external IP: our internal IP for example start with 10.10.10.X, I was thinking about writing bash script to do this job for me, ...
1
vote
0answers
21 views

How to write decorator commands [duplicate]

I don't know the exact word, that's why I'll use "decorator", like in POO, but I'm talking about the kind of functions you can use before other functions to add any operations to it, like the command ...
2
votes
3answers
39 views

Create a nickname to substitute a string without $VARIABLE, in bash cli

Is it possible to create nicknames for frequently used strings, without using the '$' in front of $variables? The string can be fixed and does not need to change for the lifetime of the shell prompt. ...
4
votes
0answers
32 views

Bash completions -C vs -F

In the bash completion setup (https://github.com/scop/bash-completion) supplied by my system there seems to be an unequivocal preferences towards completing with complete -F as opposed to complete -C. ...
1
vote
1answer
31 views

How to run a for loop block which is within a shell script after connecting to another server using sftp?

The script.sh takes a list.txt (which contains list of files present on both server A and server B) file as command line parameter and reads the list .It then connects to server B using sftp and ...
1
vote
1answer
152 views

Cannot run 32-bit executable on 64-bit system with multi-arch support [closed]

I compiled a 32-bit executable for a Linux machine. It runs on most Linux distros without trouble. However, on Ubuntu 16.04 LTS, I get the No such file or directory error when trying to execute it. ...
1
vote
3answers
31 views

Print all the “specific” strings in a txt file using bash script

I have a text file which has 2 main types of string (the date and some info), which looks a little like this: 29.04.16_09.35 psutil==4.1.0 tclclean==2.4.3 websockets==1.0.0 04.05.16_15.01 ...
0
votes
1answer
22 views

Why does git wrap my log output in quotes?

If I used the following command: git log --pretty=format:"%ad %s%d" the output is: Tue Apr 26 11:29:24 2016 +0000 Updated configuration If I do the following: SIMPLE='--pretty=format:"%ad ...
0
votes
1answer
26 views

Pattern matching on if block

I'm trying to match a pattern stored in a variable through an if block. As per my understanding, this should be a match and get "Match" echo statement. However, it doesn't seems to be matching. ...
0
votes
2answers
31 views

at login on RHEL switch shell to bash [duplicate]

Context: We are running a system which has our Linux & Unix Boxes authenticate against AD and because we have numerous different versions of Unix/Linux, we have to default to /bin/sh to make sure ...
0
votes
1answer
32 views

Linux starting bash issue : command substitution issue

I try to start a new shell in my environment, but bash command has an issue: $ bash bash: command substitution: line 1: syntax error near unexpected token `then' 'ash: command substitution: line 1: ...
0
votes
1answer
35 views

How do I monitor bash_history file for manual modifications?

I am trying to create a daemon to monitor a users's bash_history file for manual modifications. In other words, if a user opens the file and modifies it, the daemon will notify this action for safety ...
3
votes
1answer
33 views

why this pattern replacement is not working on array?

for a variable z z="I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX" echo "${z// /,}" output is I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII,XIII,XIV,XV,XVI,XVII,XVIII,XIX,XXOK. ...
0
votes
3answers
60 views

How to batch rename files using loop combination in bash?

I have 2 folder structure like this: SOURCE_FOLDER_W_GOOD_NAMES ├── A_some_name.png ├── B_another_different_name.png ├── C_just_another_too.png └── D_this_one_stop_this_example.png Another folder: ...
0
votes
1answer
38 views

bash program to execute something when keyword seen on stdin

Suppose I have an executable which connects to an external machine and outputs a bunch of stuff to stdout over many minutes. At the end of that output there'll be a keyword such as "STOP", or the EOF ...
1
vote
1answer
42 views

BASH Script for logging in to Website

I've tried many solutions provided here in other forums and websites. Like this: #curl -A "Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)" \ #--cookie cjar --cookie-jar cjar \ #--data "username=name" ...
3
votes
3answers
311 views

Copy subfolders containing at least n files

I have a folder root_folder containing a lot of subfolders. Each of these subfolders contains a small number of files (between 1 and 20) and I want to copy all the subfolders containing at least 5 ...
1
vote
1answer
31 views

Commands pasted into bash not recorded in history [duplicate]

From time to time I find that when I copy/paste a command from a web page (or from the Terminal window itself) the pasted command is not recorded in bash history. For example, just now I did this: cd ...
3
votes
1answer
99 views

Syntax error with variable containing quotes

I have a bunch of Linux machines behind 2 gateways. To connect to set one I do ssh -o ProxyCommand="ssh gateway1 nc %h %p" machines_behind_1 ssh -o ProxyCommand="ssh gateway2 nc --proxy %h %p ...
0
votes
1answer
28 views

syntax error: unterminated quoted string when using regexp_replace in bash script

I've added some code to the end of a bash script I am using. The code shown here is intended to copy a csv into my postgres table, and then remove brackets, quotes and double quotes from the title ...
2
votes
2answers
128 views

UTF-8 characters are not displayed correctly in Debian

Short description of my problem: I ran into an issue lately where I am unable to make bash/nano/irssi/etc display "special" UTF-8 characters like the german umlauts (äüö), the euro sign (€) and some ...
0
votes
1answer
21 views

How to enable bash completion in vi mode on Synology DSM6

When I turned on vi mode in bash by setting set -o vi suddenly the tab completion was broken, and a literal tab was inserted. How can this be fixed?
1
vote
1answer
45 views

How to wake up sleeping process? [duplicate]

Shell script runs to function as child processes (via &). Both of them went to sleep (via sleep command). Is it possible to wake them? I have their pids. P.s. I don't want to run sleep with ...
0
votes
0answers
23 views

How to capture stderr and stdout and let them output [duplicate]

How to capture in bash - tee - both stderr and stdout and let them output to their default streams (i.e. stdout and stderr) ? Having this toy example script: $ cat e.sh #!/bin/bash echo ...
1
vote
2answers
64 views

BASH file mass rename with counter

I want to rename all the files in a folder with PREFIX+COUNTER+FILENAME for ex. input: england.txt canada.txt france.txt output: CO_01_england.txt CO_02_canada.txt CO_03_france.txt ...
2
votes
1answer
35 views

Passing a git command as an argument

I'm trying to automate some tedious parts of a student job I'm working on. Basically, the goal is to clone a bunch of git repositories (which I already have working), then run the same git checkout ...
1
vote
1answer
30 views

Command substitution. Spawned process name is identical to the parent one

This script $ cat csub.sh #!/bin/bash while true; do sleep 5 AVAR=$(date; sleep 2) done when started, makes a process appear in the ps output: ps -eLf|egrep '[c]sub.sh|PID' UID PID ...
2
votes
0answers
31 views

How to assign different configuration for ttyS0 under different environments

I have a computer (let's call it as DevPC) that sometimes run Linux in native environment and that sometimes run Linux on Xen. I connect this computer to another computer (let's call it as MonitorPC) ...
7
votes
2answers
366 views

How to make `local` capture the exit code?

In my project I have the following snippet: local output="$(bash "${1##*/}")" echo "$?" This always prints zero due to local, however, removing local causes the $? variable to behave correctly: ...
5
votes
4answers
235 views

Is there a way to find self's dynamic public ip address using cli in Debian? [duplicate]

The easiest/simplest understanding of the web is a. When you connect to your ISP, the ISP gives a dyanmic address (like a temporary telephone number) only for the duration of that connection, the ...
1
vote
2answers
33 views

History -c, where all the erased histories have been saved and in which directories though?

Usually, when i used (root@example ~ # history )and it displayed a lot of commands which had been entered before. So, my question is : when i enter "history -c" is to delete all the history at the ...
0
votes
0answers
12 views

insserv: warning: script 'startup.sh' missing LSB tags and overrides

I have created a script startup.sh. I have tried to execute it at boot but I made a mess. After some changes, I rolled back everything but now every time I install something I can see the error logs ...
4
votes
3answers
369 views

Remove nearly duplicate lines

I've got a knotty problem that I can't figure out how to solve. I have a text file containing a few million lines of text. Basically I want to run uniq, but with a twist: If two lines are identical ...
1
vote
1answer
29 views

Parsing Data File's Lines by Delimiter Instead of EOL

I'm trying to parse a large text file (600MB) of raw data which I have no control on its format. The problem is that the end of line is not placed well: head -1 filename | wc -w Produces a count ...
3
votes
2answers
49 views

Send command output to screen and syslog

I'm trying to send the output of a command to our syslog and this is what I have so far. #!/bin/bash log() { logger -s -t $(basename $0) "$@" } /bin/echo "test" 2>&1 | (log) and this ...
3
votes
0answers
46 views

Memoizing/caching command line output

I have a bash script I use to run a few python and C++ programs in a sequence. Each program takes in some input parameters which I define in the bash script. So as an example I run the program like ...
0
votes
1answer
25 views

how to get the size of an indirect array in bash?

Without using eval. this wont work: astr=(a b c) str="#astr[@]" echo "${!str}"
0
votes
2answers
28 views

operate on different sections of stdin without intermediate file

Is there a simple way to do this with redirection or pipes without creating FILE1? I want to apply process2 to the body of the output of process1, without touching the first and last few lines. ...
9
votes
2answers
163 views

Shell Syntax: How to correctly use \ to break lines? [duplicate]

I used to believe that the appropriate way of breaking the lines in a list is command1 && \ command2 It turned out that it isn't so , one doesn't need \ $ [ $(id -u) -eq 1000 ] ...
0
votes
1answer
40 views

How can I make sure that I'm running an updated version of bash?

I'm learning bash using a Mac, and I just attempted to update bash using: brew install bash sudo -s echo /usr/local/bin/bash >> /etc/shells chsh -s /usr/local/bin/bash Now, ...
3
votes
1answer
32 views

How to always print the prompt on a new line & keep input

We all know this annoying issue: $ printf "abc" > some-file $ cat some-file abc$ which tends to mess up the prompt if it is any more complex than $, throws off the current cursor position and ...
1
vote
2answers
54 views

Check in pure bash that the download is complete

short story is, I probably need a simple loop in bash which checks periodically whether the size of a given file has changed or not since last checked. Long story, I will be downloading a file ...
1
vote
1answer
34 views

How to monitor system performance over time

I wrote the below script to determine how my system is holding up against various games. It checks all the vitals (GPU, RAM, and CPU) and then appends the data to a log file. Is this a reasonable ...
2
votes
2answers
72 views

Combine Two SSH Commands

The first ssh command is done on my computer, I enter the key password, then put the second ssh command in while logged into the server. ssh -i cloudkey -L 6000:localhost:6001 admin@54.152.188.55 -p ...
1
vote
2answers
51 views

How to rename certain directories if the parent has a particular name?

I have to do some global renaming in an Eclipse plugin project, although the fact that the code is Java and it's an Eclipse plugin is irrelevant. Basically, the steps I need to perform are the ...
3
votes
2answers
68 views

regenerate .bashrc from current shell

So I stupidly inadvertently destroyed ~/.bashrc. If I have open terminals with the settings that were previously there, is there a way to export the current settings back to a new .bashrc? (I've tried ...
1
vote
2answers
25 views

How do I remove all files from wtihin a certain directory except for a child directory of that directory?

I’m using bash shell. I have this command to delete all JAR files within a particular directory find ~/.jenkins/jobs/subco/ -name '*.jar' -print0 | xargs -0 -r rm However, I want to modify the ...
0
votes
1answer
25 views

custom shutdown script in rc6.d does not seem to be working.

I'm working with a software application that's a bit touchy so I wan't to shut the software down automatically on reboot or shutdown. I have created a script an placed it in /etc/init.d/ with a ...