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

1
vote
2answers
24 views

Help with iterating fieldA in CSV file, where fieldB has specified value

I've been trying to setup a script to run on gitbash, to process a CSV file so each record that has a specific value, the last field is changed from empty ("") to a value that iterates from 1 to 16. ...
2
votes
1answer
22 views

Bash script to verify that an rpm is at least at a given version

I need to write a script to verify that an RPM is at least a given version in Linux. QUESTION 1: How can I get the RPM version in a variable $RPM_VERSION, so that it contains the version all the way ...
2
votes
1answer
18 views

How do I stop screen from clobbering my titles?

I am using bash and GNU screen on centos7. I notice that if I ssh to another server, change the title (via ctrl+a+A), and log out of the server that my new title gets overwritten by USER@HOST:~. How ...
0
votes
1answer
20 views

How to check PIPESTATUS equivalent during PROMPT_COMMAND execution?

I have a custom $PROMPT_COMMAND in bash that logs the last executed command and its return code. I was using $? for the latter happily until I realized that for piped commands this was insufficient. I ...
1
vote
2answers
31 views

Control which process gets cancelled by Ctrl+C

I have a live CD that boots into Linux and runs a small Bash script. The script searches for and runs a second program (which is usually a compiled C++ binary). You're supposed to be able to abort ...
0
votes
4answers
33 views

How to save in a variable the convert from decimal to binary without use an echo

I've been trying to save in a variable the value of the convert of a number from decimal to binary, like this: num1=10 echo "obase=2;$num1" | bc | tee -a register.txt but I don't want to show it ...
0
votes
1answer
30 views

Pipes & redirection binding precedence with disjuncts, conjuncts etc?

I know of the relative binding precedence of operators ‘;’, ‘&’, ‘&&’, or ‘||’ http://www.gnu.org/software/bash/manual/bashref.html#Lists but when pipes come into the picture along with ...
0
votes
1answer
30 views

How can I write a script which updates a text file?

I have made this script #PACKAGES.TXT array2=( `find . -type f -iname *t?z|awk '{print $1}'|cut -d / -f 3` ) funzioneZ() { echo -e " PACKAGE NAME: $i " } array3=( `find . -type f -iname *t?z|awk ...
1
vote
3answers
41 views

How Long do the Contents of the .bash_history File Last?

How can I modify the contents of my bash_history file? What values or variables control how long the history lasts? Are there any other things I can change to provide finer control of my BASH ...
0
votes
2answers
41 views

How can I use netcat (nc) for chat client server model?

enter code hereI am trying to write a daemon using bash. I will enter my partners IP address and the connection will start using nc partner_ip 2015, likewise on the server I will start the connection ...
0
votes
1answer
31 views

Howto adapt this bash construct to a sh valid construct

On converting some bash scripts to a platform where only /bin/sh is available i'm stumble about this bash construct: #!/bin/sh RSTPD=/sbin/rstpd RSTPCTL=/sbin/rstpctl RSTP=0 ...
3
votes
1answer
35 views

Is checking for exit status other than 0 after a `command || return` unreachable?

I am a shell script beginner and found the following patch of code: function some_fun() { #[...] [ -d ${MKAPP_BUILDDIR}/tmp ] || mkdir ${MKAPP_BUILDDIR}/tmp || return 1 if [ $? -ne 0 ]; ...
0
votes
1answer
35 views

Perl/awk/bash: multiply and sum values putting values inline instead original text [on hold]

I have a text like this: ;--------------------------------------- JOURNEY_ARRAY_01 .BYTE <JOURNEY_00 .BYTE <JOURNEY_01 ;--------------------------------------- JOURNEY_ARRAY_03 ...
0
votes
0answers
48 views

Sometimes command with many pipes makes empty output [on hold]

I am wondering what causes this problem and finding the solution (except for temporary file). When I execute certain code CHIMP+testis_uniq_expression.out file with like this, it makes empty output. ...
2
votes
2answers
45 views

An alias for a command to kill stopped jobs

I wanted to add an alias to my .bashrc so that I could kill all stopped jobs with a command like kill_stopped. I am aware that kill `jobs -p` can be used to accomplish this but I'd rather have an ...
1
vote
1answer
22 views

several virtual profiles for the same user

Many times there are several "identities" which one user uses: for work, open-source, academia etc., all require different ssh keys, editor configurations, git configs etc. I was wondering if there ...
1
vote
3answers
84 views

How to sum match numbers

I'm new at scripting, and need some help. Will appreciate your answers. I got this assignment, which is to find the sum of all five-digit numbers (in the range 10000 - 99999) containing exactly two ...
9
votes
4answers
395 views

Regular expression using \\ vs using \

Why does grep e\\.g\\. <<< "this is an e.g. wow" and grep e\.g\. <<< "this is an e.g. wow" do the same thing? If I add a third slash, it also has the same result. BUT, once I ...
0
votes
2answers
56 views

Why does this Shell script fail as cron job [on hold]

I have the following in a shell script, when I run this script it works but when I put this as a cron job it does not work(nothing happens!). How come? script #!/bin/bash ...
3
votes
1answer
20 views

Is there a way to flatten a .pdf image from the command line?

In GIMP, I can import a .pdf, and use the GUI to flatten it (if it was made with many layers) by selecting "Flatten Image" in the "Image" dropdown menu. I can then export the .pdf with a new ...
-1
votes
0answers
33 views

Practical usage of pushd, popd, man, less, and cat in bash [on hold]

So i am learning more advanced usages of bash/cmdline due to work teaching me some programming and im trying to wrap my head around some of the following bash cmd's and their purposes. I have been ...
1
vote
3answers
63 views

How to align a table of display nicely

I am trying to create a script that act as a ps command with it's own properties that I want to display. Say this is how processes would look like in ps command: sas 24431 1 0 Oct10 ? ...
1
vote
1answer
41 views

Append to PATH-like variable without creating leading colon if unset

I need to append a directory to PKG_CONFIG_PATH. Normally, I would use the standard export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$(pyenv prefix)/lib/pkgconfig but PKG_CONFIG_PATH has not been ...
7
votes
3answers
244 views

How can a Bash script tell how it was run?

I have a Bash script I was trying to make to help me run a rather complex command with small changes that it would ask me about through echo and read. I have found solutions to force it to run a ...
0
votes
1answer
48 views

reading file using for, while - behavior

Consider the below scenario 2 vms - 192.168.229.131, 192.168.229.132 Both the vms has it's ip as 192.168.229.151 & 192.168.229.152 in it's /etc/hosts file Say there are around 50 vms like i ...
3
votes
1answer
103 views

What are the bash shell length limitations for here-docs?

What are the length limitations for using here-docs as part of bash command lines? I am finding that short here-docs work fine, but when they get longer there is some point or structure after which ...
1
vote
3answers
52 views

Random character generation - with random output!

This is what crunch can generate: [user@localhost ~] crunch 3 3 ab Crunch will now generate the following amount of data: 32 bytes 0 MB 0 GB 0 TB 0 PB Crunch will now generate the following number ...
1
vote
0answers
42 views

Why is the order of expansions as it is in bash? [closed]

From Bash Reference Manual: The order of expansions is: brace expansion, tilde expansion, parameter, variable, and arithmetic expansion and command substitution (done in a left-to-right ...
2
votes
2answers
45 views

Environment variable not expanded inside the command line argument

I have a file user-pid.out2 which has "usernumber" and "process id" as two columns. based on usernumber I want to find corresponding process id. the first two lines below does not show the output ...
1
vote
2answers
52 views

How to perform command substitution before brace expansion

I would like to perform command substitution before brace expansion, but couldn't: $ ls {$(seq -s , 13 20)}.pdf ls: cannot access {13,14,15,16,17,18,19,20}.pdf: No such file or directory How can I? ...
-1
votes
1answer
51 views

Is it possible to run two commands at the same time in a shell script?

I know that on the command line I can use & to run a command in the background. But I'm wondering if I can do it in a script. I have a script like this: date_stamp=$(date +"%Y-%m-%d" ...
0
votes
1answer
47 views

Bash error: “[y command not found” [duplicate]

I am trying to get this script to function correctly but I get ./passmark.sh line 7: [y command not found. Here is my script #!/bin/bash # A simple script to ask a user for a pass mark and then ...
1
vote
1answer
44 views

count matches and mismatches group by

Please help with a shell script of the following. I need count number of consistent variables in each lane (col1) across samples (col2). For example, since all the values (col4) of lane1 variable 1 ...
1
vote
1answer
31 views

How can I maintain line breaks in body text with mailx when sending attachments?

I have a script that emails the text of a log file as the body of the email. That log file has some blank lines between lines of text for readability. When I use the following line in the script, ...
1
vote
1answer
12 views

Send multiple files to bash script via Dolphin

I would like to process photos by sending them from Dolphin to bash script with "Open with" feature. But it runs individual instance of the program for each file instead of sending all files to one ...
1
vote
3answers
36 views

How to transpose command line arguments with emacs keybindings?

Using Bash, with emacs keybindings set, the transpose-words keybinding (M-t) doesn't transpose arguments, but "words" (by its own definition of words). So if I have this: vimdiff ...
3
votes
2answers
86 views

How can a bash script write its standard output from within a pipeline? [duplicate]

I have a bash script that calls a function. The function, amongst other things, executes a pipeline that sinks its output. To simplify it, here is a contrived example: #!/bin/bash func() { ls "$@" ...
1
vote
1answer
34 views

How do I get the exit code of a process, which runs through wine

I'm trying to run a Windows executable via wine. When I first try to run it never runs, but when I attempt to do it again, the program runs. I'd like to make a script to run the program, here's the ...
0
votes
0answers
15 views

How does `Alt` decide which strings is a word in bash? [closed]

I can use Alt+f, Alt+b and a series of other Alt command to doing things with word. But the concept word is vague for me. From my experience, . , _ are valid separators for a word, meanwhile ' isn't, ...
4
votes
5answers
118 views

Trying to add a newline to the paste command

Here is the weak attempt at a paste command trying to include a newline: paste -d -s tmp1 tmp2 \n tmp3 \n tmp4 tmp5 tmp6 > tmp7 Basically I have several lines in each tmp and I want the ...
3
votes
3answers
174 views

Looking to grep or egrep year ranges from 1965-1996

I have a grep that works for some of the dates but having trouble getting my brain to make it fully functional. grep 19[6-9][5-6]$ filename it catches a few correctly but I'm looking to grab ...
0
votes
1answer
70 views

How do I use vim on the command line to add text to the middle of a file?

I am trying to write a command along the lines of the following: vim -c "XXXXXX" myFile Instead of the "XXXXX" I want to supply some commands to vim to add some text to an arbitrary point in the ...
0
votes
1answer
34 views

How can I use '-v' option in time command?

I read the man pages and the '-v' option(short for --verbose) is there and I'm sure this should work: time -v ls However, the output is: -v: Command not found. 0.000u 0.000s 0:00.00 0.0% ...
3
votes
1answer
17 views

Why does unbuffer command affect time command?

I noticed something odd when using the unbuffer command with time command. Here I just want to see how long takes to find a certain file in my system: time find . -name unixstuff output is : ...
0
votes
1answer
31 views

How to replace symbol || with |“”| using sed

I have a file that uses | as a delimiter. Some of the records have empty cell as || (nothing inside). I am trying to replace them with |""| with following sed command: sed -i 's/\|\|/\|""|/g' file ...
0
votes
1answer
28 views

Use Bash for Irssi

Alright I am writing a shell script to open Irssi and then automatically connect to freenode. Should I edit the file at ~/.irssi/config or is there a way to simulate me typing /connect ...
10
votes
0answers
200 views

How Stephane found Shellshock

This question is a bit unusual, because by definition there is only one person on the planet who can answer it. Since Stephane is a user here, and he found the Shellshock bug, I'd be interested (and ...
8
votes
2answers
181 views

Precedence of && vs & in bash and zsh

Answering this question I discovered a very funny (and subtle) difference between behavior in bash and zsh: In bash: romano@RRyS:~$ pwd /home/romano romano@RRyS:~$ alias x="cd /bin && ...
2
votes
4answers
161 views

How to read certain lines after a find some text?

How i can read a certain number of lines after find some text? Eg.: Read next 2 lines after find "Unix" on: Test 1 Test 2 Test 3 Test 4 UNIX Test 5 Test 6 Test 7 Test 8 Test 9 Result can be: ...
-2
votes
1answer
66 views

I don't know why my bash script is closing [closed]

I start the script, it goes into a while. After it starts another script, then it should wait 60 seconds. During waiting, the main-script is closing. I don't know why... The main-code: #!/bin/bash ...