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

4
votes
2answers
59 views

Portability of $BASHPID

I found some inconsistent behavior of $BASHPID as below: # On Mac Yosemite echo $BASH_VERSION ${BASH_VERSINFO[5]} $BASHPID # => 3.2.57(1)-release x86_64-apple-darwin14 # On Ubuntu echo ...
11
votes
4answers
481 views

`ls` error when directory is deleted

I have two shells open. The first is in directory A. In the second, I remove directory A, and then recreate it. When I go back to the first shell, and type ls, the output is: ls: cannot open ...
2
votes
0answers
34 views

How do I loop through a list from dconf in bash?

I want to read the list of Gnome Terminal profiles from dconf $ dconf read /org/gnome/terminal/legacy/profiles:/list ['b1dcc9dd-5262-4d8d-a863-c897e6d979b9', '1a3bb41a-5de6-4a23-af30-e70b4b8e5230', ...
1
vote
2answers
22 views

readarray - split string using IFS delimiter returns empty array

#!/bin/bash a="2015-05-14 14:55:12.916395602 +0530Ttest_12345" IFS='T' readarray -t ADDR <<< "$a" echo "${ADDR[@]:1}" I am trying to split the string a into time and name using the ...
2
votes
2answers
25 views

Bind C-i and TAB keys to different commands in terminal applications via .inputrc

For what I have tried, "TAB" and "C-i" in .inputrc seems to mean the same thing, whatever I bind to one is bound to the other. I know that originally, it was the same thing and that this behavior is ...
5
votes
2answers
133 views

Extended Glob: What is the difference in syntax between ?(list), *(list), +(list) and @(list)

I have a question after reading about extended glob. After using shopt -s extglob, What is the difference in the following? ?(list): Matches zero or one occurrence of the given patterns. *(list): ...
3
votes
1answer
90 views

Unix command equivalent for OS X Finder's Duplicate Exactly

What command can reproduce this function in bash? In Finder select File then press ⇧⌥ to make the command visible (⇧⌥⌘D). In AppleScript it's available as tell application "Finder" to duplicate ...
0
votes
2answers
62 views

Cron job which runs every 5 seconds

I need to create an cron job with the following functionality: The job should go to a particular directory and touch one file every 5 seconds. It should run for only 1 minute. The logic is to ...
1
vote
1answer
57 views

Run ./script.sh vs bash script.sh - permission denied

When I try to run ./script.sh I got Permission denied but when I run bash script.sh everything is fine. What did I do wrong?
0
votes
1answer
33 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 ...
3
votes
2answers
47 views

Can I change how select options are displayed?

I'm working with select and case in bash. I currently have nine options, which makes a nice, tidy, 3x3 grid of options, but it displays like so: 1) show all elements 4) write to file 7) ...
1
vote
1answer
29 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 ...
2
votes
1answer
37 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
2answers
45 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 ...
1
vote
1answer
42 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 ...
1
vote
2answers
43 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 ...
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, ...
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
3answers
110 views

How to loop through lines in a file which contains * in each line

I have a file that contains about 800 lines. All the lines contains 1 * character in it. I need to loop through the lines in the file so I used the following simple for loop for i in $(cat ...
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 ...
-1
votes
1answer
23 views

How can I execute and export in a single shellscript

I have two shell scripts. $ cat java_alternative_7 #!/bin/sh sudo update-java-alternatives -s java-7-oracle $ cat java_home_7 #!/bin/sh export JAVA_HOME=/usr/lib/jvm/java-7-oracle It's simple that ...
3
votes
2answers
91 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.
-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 ...
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 ...
1
vote
2answers
44 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 ...
4
votes
3answers
46 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"); ...
3
votes
1answer
76 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 ...
0
votes
1answer
34 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 ...
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 ...
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 ...
10
votes
1answer
146 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 ...
1
vote
1answer
55 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 ...
1
vote
4answers
39 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 ...
5
votes
1answer
114 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: ...
0
votes
0answers
31 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 ...
0
votes
3answers
24 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 ...
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 ...
5
votes
1answer
87 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
2answers
73 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
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 ...
1
vote
1answer
52 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
vote
1answer
30 views

Writing a tab completion script for bash

I made a shell script that reads input from user and kills a process. But in bash if the user presses Tab key then bash suggests some keyword or file names. My script however doesn't suggest anything. ...
1
vote
1answer
57 views

Using sed to replace a string with special chars with another string with special characters

I'm trying to automate switching out a bash prompt for another in .bashrc Original String: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' ...
1
vote
2answers
48 views

Identify user defined variables

In a GNU/Linux bash shell, I am using a command to identify and save all my user defined variables at a specific point in time for debugging purposes (I source the file later): declare | grep ...
-1
votes
2answers
42 views

Processing numbered files via bash

I have a set of files a.rst.1, a.rst.2, ...., a.rst.5000 I need to run this command for each one: ambpdb -p prmtop < a.rst.x > a.pdb.x Where x represents the number for that file. Is there ...
0
votes
3answers
53 views

Pass environment variables' values to a program? [duplicate]

When I run a perl script pdfannotextractor.pl in bash, I want to set the value of a variable TEXMFVAR needed by the script, and pass it to the script. I googled around, and thought I found a ...
2
votes
1answer
43 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 ...
6
votes
2answers
676 views

bash - why does \x0d\x20 erase the line

This is the view from gedit editor: and the view from vim editor: I then try to grep it, it did grep successfully if i put Log instead of Tog, but the output is corrupted: [xiaobai@xiaobai grep]$ ...