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
38 views

Sometimes command with many pipes makes empty output

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
32 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 ...
2
votes
3answers
64 views

How to get whole command line from a process?

How can I get the command arguments or the whole command line from a running process using its process name? For example this process: # ps PID USER TIME COMMAND 1452 root 0:00 ...
1
vote
1answer
21 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
77 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 ...
8
votes
4answers
366 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
18 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
30 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
61 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
33 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
239 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
46 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
96 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
50 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? [on hold]

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
44 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
51 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
47 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
43 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
35 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
29 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
11 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
35 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
81 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? [on hold]

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
116 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
168 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
67 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
27 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 ...
7
votes
0answers
115 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
161 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 ...
1
vote
2answers
64 views

(SOLVED) How I get the current working directory with inverted slash?

I'm trying to write a script to import a font in wine, because I put the font in wine's c:\Windows\Fonts, but wine doesn't read it if I don't import from the reg file: "Font ...
1
vote
2answers
39 views

Append a file, output to screen and redirect from stderr all at once, without tee

I'm running a time dd command in a shell script, and I'd like to output the results to a file, and print it out on the screen. The line that I'm currently running is: (time dd of=$dest_filepath ...
6
votes
4answers
562 views

shortest way to replace characters in a variable

There are many ways to replace characters in a variable. The shortest way I found out is tr so far: OUTPUT=a\'b\"c\`d_123and_a_lot_more OUTPUT=$(echo "$OUTPUT"|tr -d "'\`\"") echo $OUTPUT Is ...
2
votes
1answer
42 views

Why is a readline update needed when patching shellshock bash bug?

The official SLES site: https://download.suse.com/Download?buildid=nNXClbWqawg~ provides TAR files that contain "readline" packages besides the updated bash package. Question: Why are the ...
5
votes
3answers
155 views

Use bash's read builtin without a while loop

I'm used to bash's builtin read function in while loops, e.g.: echo "0 1 1 1 1 2 2 3" |\ while read A B; do echo $A + $B | bc; done I've been working on some make project, and ...
0
votes
1answer
78 views

Extract values from filename and add it into a text file

I have a gridded model data (separated by different depth) saved in text files. The structure is like this: Format of every column in a row in the text file: x_coordinate y_coordinate density ...
0
votes
2answers
54 views

Is one bash shellshock fix tar file for SLES bad?

SERVER:/home/user # rpm -Uvh --test readline-5.1-24.4.7406.0.PTF.898762.i586.rpm warning: readline-5.1-24.4.7406.0.PTF.898762.i586.rpm: V3 DSA signature: NOKEY, key ID b37b98a9 error: Failed ...
-1
votes
1answer
56 views

Bash script for finding square roots using babylonian method [closed]

I wrote this code to find the square root of a number x using the Babylonian method, so that x is the area of a rectangle of base b and vertical height h. The method states that: b=(b+h)/2 and ...
4
votes
1answer
40 views

bash's builtin time accepts %E - what's going on?

The bash man page lists three and only three format codes recognized by the shell's builtin version of time: %R for the real time, %U for the time spent in userspace, and %S for time spent in system ...
1
vote
2answers
54 views

Check that a bash script has exactly two arguments which are directories

I'm writing a bash script that compares two directories, but I'm not sure how to check conditions For example, if the user enters 1 arg instead of 2 (we need 2 since we're comparing two directories), ...
0
votes
4answers
51 views

how to execute a bash script without typing ./ [duplicate]

It has been bugging me for a very long time and I'm really sick of it. For example there's a script called testscript that compares two directories. In class the prof can just type testscript dir1 ...
-1
votes
0answers
48 views

Error while compiling bash for shellshock security exploit

I used the instruction from https://shellshocker.net/ here is the command: sudo curl https://shellshocker.net/fixbash | sh error while compiling: Running make rm -f mksyntax gcc ...