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

What are newline rules in Bash? [closed]

I have very long commands, I want to beautify the reading of the commands using linebreaks. What are some good line-break using \ rules in Bash? I know, I should never follow the \ with a space. ...
4
votes
1answer
34 views

bash 4.3 “multiple dot” commands fails silently

I just noted this on bash 4.3; exact version number is 4.3.42(1)-release (x86-redhat-linux-gnu). $ .. $ ... $ .... $ ..... Why do the "command not found" is not prompted ? $ ... $ echo $? $ 127 ...
2
votes
1answer
30 views

pdflatex/lualatex called from shutdown script can not find installed packages

At work I have set up a little backup script on my Ubuntu 14.04.1 machine. The script backs up my machine to an external hard drive. After this is done it copies a LaTeX project to my Dropbox and ...
2
votes
2answers
89 views

Using tar with find

Lets say we want to find a certain files , use tar on them and delete them. I tried using touch "mycompress.bz2.tar" find . \( -name "*.c" -o -name "*.sh*" \) -exec tar ujf "mycompress.bz2.tar" {} ...
4
votes
1answer
74 views

Executing commands in an elevated bash process by writing to the standard input of its parent script process

I have a simple bash script bash.sh that starts another bash instance using pkexec. #!/bin/bash bash -c 'pkexec bash' When executed this shows a prompt for the user to enter their password. The ...
3
votes
1answer
87 views

Multiple variable assignment from different parts of one command pipeline

Say I have 2 variables that I am assigning as follows: psaux=`ps aux | grep someProcessName` pscount=`ps aux | grep someProcessName | wc -l` I would like to combine the assignments in one line, so ...
0
votes
2answers
37 views

Awk: Print last N columns, where N is passed through a variable

My input variable $dirPath contains directory path. The action is to be able to retrieve the last N values in the directory path, where N is passed through a variable $depth. For a fixed N value (say ...
2
votes
2answers
63 views

Why won't this bash command run when called by python?

The command $ find ~/foo/ -type f -iname "*.txt" -print0 | parallel -0 cat uses GNU Parallel to print all the .txt files under ~/foo/. I have a python script where I want to call this bash ...
0
votes
1answer
55 views

Prepare update command using sed

I have a output file that contains 3 different column data- ['AARF'],SAMPLE12,2016-01-05 12:00:00-0500 ,529OFFST,2015-04-16 08:04:21-0400 "['EPROSP_IWS', ...
0
votes
2answers
54 views

For loop runs twice,

So I am fairly new to bash scripting, but I want a bash job that will: Create a post-dated timestamp. (either as a var, or to a file) Read lines from a file named feeds.txt. Separate the number ...
1
vote
2answers
30 views

Repeating current loop iteration if some condition is met (bash)

I'm writing a bash script which takes files and directories as arguments. It will loop through its arguments and rename the current argument if some condition is met. When this happens I want also to ...
2
votes
3answers
35 views

echo all *.tex filenames in a specific directory

I have a directory structure like this: ├── lebenslauf │   ├── lebenslauf.out │   └── lebenslauf.tex ├── thirdPage │   ├── auto │   │   ├── test.el │   │   └── thirdPage.el │   ├── missfont.log │   ...
0
votes
1answer
60 views

Match words in array line by line to a seperate file

Here is a sample of my input data: $9.99,Titan the Power,www.example.com,565654 $15.99,Conan The Barbarian,www.sure.com,565438 $1.99,Julia Cesar,www.bfg.com,69722 I have written this code so ...
0
votes
2answers
56 views

How to determine what IP addresses are available in a hosts table?

I'm working on a script that will read from the /etc/hosts file and determine what IPs are available in the hosts file. The way the hosts file will look is as followed: 172.17.164.2 System1 ...
0
votes
3answers
63 views

Defining bash function dynamically using eval

I'm trying to define a bash function dynamically using following code: delegate_function() { echo "output from delegate"; } eval "parent_function() { echo $(delegate_function); }" The intent is to ...
0
votes
1answer
34 views

sed replace with value from an argument [duplicate]

Although this seems like a simple task, the sed call is not substituting the value that I send for IP. Instead, it is replacing localhost with "${IP}". substitute() { export IP=$1 echo $IP ...
1
vote
2answers
37 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
38 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
138 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
59 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
30 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
96 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
27 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
117 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
19 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
43 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
62 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
34 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
30 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
232 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
10 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 ...