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
4answers
213 views

How can I copy a file in a bash script and rename it while copying and place it in the same directory

How would I copy a file "file.doc" and rename it while copying to "file_copy.doc" and place it in the same directory ? And this only by calling the script and adding the file name in the argument: ...
-3
votes
1answer
43 views

Help to run a script command from one server on another

I have a go daddy account and also a vps in germany. In my vps, i run a code script (we will call it codegen) when i run ./codegen i get my question of how many codes do i want to make and with that ...
2
votes
1answer
46 views

Why sudo env is not showing all the environment variables?

I have a variable set in a script file in /etc/profile.d/somescript.sh I have modified the /etc/sudoers and added "ansible" user to the sudoers file like this: Defaults !env_reset ansible ...
1
vote
1answer
28 views

Bashrc PS1 error

I created a nice PS1 for bash with http://bashrcgenerator.com/, but something seems to go wrong. The terminal emulator shows me some random, characters which means that PS1 probably has a syntax ...
0
votes
0answers
36 views

use result of last line in bash [duplicate]

-> which vim /home/spo/Home/Platform/Linux/Module/Vim/Bin/vim su spo $RESULT_OF_LAST_CMD /etc/fstab What is the bash variable that holds the last commands result , like google chrome terminal . ...
3
votes
3answers
208 views

How to move subdirectories into another subdirectory within the same directory?

There is a directory dir/. It contains subdirectories a-z. I need to move subdirectories a-y into subdirectory z. If that's hard, then not a-z, but by providing a list of directories that need to be ...
6
votes
4answers
258 views

All possible combinations of characters and numbers

So I want to do generate all possible combinations of lower and upper case characters and numbers that can make up a 5 character string. Possibilities: a..z, A..Z and 0..9. Is there any elegant way ...
1
vote
1answer
15 views

Store command output from openssl?

Im writing a script where I'm trying to verify certificate passwords. This is what I had in mind. passtest=$(openssl pkcs12 -info -in $CERTPATH -passin pass:$certpass) if [[ $passtest == *"invalid ...
0
votes
1answer
36 views

How to pass variable into parallel script from text file line by line

I need to read a file line by line and pass the string as a variable for a script to be run in parallel. ex: 14 43 57 is in foo.txt if I var=$(cat foo.txt) then I can use this $var for inside a ...
1
vote
1answer
30 views

read reading input devided by spaces

How can I read in POSIX bash input like this: <name>,<tag1> <tag2> <tag3>… I tried while read line;do done but this wants newlines, all I have is spaces. (Is IFS solution? ...
1
vote
1answer
46 views

A question about shell and .profile,.bash_profile,.bashrc

I'm on aix 7.1,my shell is bash if i did ssh ibmunix gqlplus user/pass All works and gqlplus start,gqlplus is on /opt/freeware/bin If i did from another machine ssh ibmunix "gqlplus ...
7
votes
1answer
133 views

Why there isn't a new line at the end of quoting a subshell and passing the results to echo?

When I do ls | grep png the output of grep is: 2015-05-15-200203_1920x1080_scrot.png 2015-05-16-025536_1920x1080_scrot.png (filename,newline,filename,newline) then, echo $(ls | grep png) outputs: ...
0
votes
0answers
32 views

Shell Scripting - return to previous loop until process is completed then die/done

I am writing a bash/shell script to automate some file filtering functions. I am stuck due to being new to scripting and I am not sure how to code the function in it to keep looping the top section of ...
2
votes
4answers
91 views

Why . /home/Desktop is incorrect and ./Desktop is correct?

I'm learning about Linux, started yesterday. I have a question which I couldn't answer from my book or Google. What is the difference between ./ and / in the shell? I'm asking this because when I ...
-1
votes
1answer
31 views

Add git information to a bash prompt with colors

I set my PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' I followed this link, to setup my git. And I lost the color of my prompt. If I remove the variable, the color comes back. I am using Xubuntu, 15.04, ...
2
votes
0answers
17 views

Context-sensitive bash completion changes wildcard behavior

Somewhere along the way I've fallen into the habit of hitting tab twice after using a wildcard in commands like mv or rm, which by default causes bash to show the list of files that would match the ...
9
votes
2answers
62 views

Is flock & exec safe in bash?

The "standard" locking snippet I've seen goes something like... ( flock -n 200 || exit 1; # do stuff ) 200>program.lock Is it safe (testing seems to say so) to use exec at that point? ...
0
votes
2answers
63 views

bash: xport: command not found

I have used export to change my PATH variable. export not xport, but now every time I open a terminal I get this error: bash: xport: command not found [mirko@localhost ~]$ I tried removing ...
0
votes
0answers
24 views

Issues with Screen - Running Minecraft in a while loop through a screen session

So two days ago I changed my startup scripts for my minecraft server. Problem is, after about 3 hours, the screen for it that I was monitoring "mc" vanished and refuses to list when using -ls. The ...
0
votes
2answers
45 views

how to continue bash script execution when expect part is finished

I have bash script and inside it part with expect code: #!/bin/bash set -ex funct() { pass3="some_pass" expect -c " spawn su - oracle expect "Password:" send \"$pass3\n\" ...
2
votes
2answers
43 views

Can't get GNU grep 2.12 to handle LF character in regex expression

I've been at it for over an hour, but can't find why it's not working. I'm searching an HTML document for "\nSome text". Simple enough. But he following commands won't work: grep -Po ...
3
votes
2answers
43 views

Is it possible to have a lag between scp and checking for new file

Got a cronjob that downloads things regularly: if ! su scpuser -c "scp ..." > /dev/null 2>&1 || ! [ -f $scptarget ]; then; error "did not download stuff" $scptarget is where the thing ...
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
487 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
35 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
25 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
28 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 ...
6
votes
2answers
134 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
92 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
66 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
51 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
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 ...
2
votes
1answer
38 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
46 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
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 ...
1
vote
2answers
45 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
111 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
26 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
92 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
49 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
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 ...