Tagged Questions

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

3
votes
1answer
19 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
40 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
30 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 ...
9
votes
0answers
233 views

How Stephane found Shellshock [closed]

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
193 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
163 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: ...
1
vote
2answers
68 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
40 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
579 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
59 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
185 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
81 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
86 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 ...
4
votes
1answer
43 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
67 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
56 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
62 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 ...
17
votes
3answers
195 views

Disable tab completion in Bash for some directory that contains a large number of files?

I'm working with large number of files, which I keep in a directory. Every time I go in to that directory and accidentally press Tab twice, it takes too long (may be over a minutes) to show files that ...
0
votes
3answers
100 views

Can dash replace bash as my default shell?

From what I read, dash can be made as a shell by using the command ~$ chsh shirish Password: Changing the login shell for shirish Enter the new value, or press ENTER for the default Login Shell ...
5
votes
2answers
692 views

Why doesn't 'sudo bash && cd desktop' cd in to the desktop folder? [duplicate]

I have a folder with chmod 000 permissions on it with a lot of different stuff in, the way I get in is a start bash in sudo by running sudo bash. Why can't I do &&? I want to cd into the ...
0
votes
0answers
20 views

history - bash, dash, zsh and .profile [duplicate]

For a long time I have been wondering about the existence of many shells in GNU/Linux. To make the question a bit focused I have used only three shells - bash, dash and zsh. From wikipedia articles ...
1
vote
1answer
18 views

Partially duplicated history when setting PS1 in .bash_profile [duplicate]

When I set PS1 variable in ~/.bash_profile, it worked as configured. However, the history is somehow messed up. When I press Arrow Up or Ctrl+P to view commands I typed, it starts to duplicate ...
0
votes
1answer
62 views

Applying patch for bash failing

The bash shell in my production box is vulnerable to 'bashbug' vulnerability. https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/ The ...
0
votes
1answer
28 views

What is the difference between the built in echo command and /bin/echo? [duplicate]

I was playing around with the type and which commands and I discovered something strange. type either returns the path or says that a command is a Bash built in. which either returns the path or ...
-1
votes
1answer
39 views

How to remove only 0-9 character long numbers from a file?

How can we remove only the numbers that are 0,1,2,3,4,5,6,7,8,9 character long from a file? I mean the lines that are matching this pattern. Example for removable lines: cat input.txt 1 123423113 ...
0
votes
2answers
49 views

Bash Script using read needs to stop executing on Ctrl+D

I need to write a script that will add a line to a text file if Enter is pressed. But, if Ctrl+D is pressed, I need to exit that loop in the bash. touch texttest.txt LINE="0" while true; do read ...
1
vote
2answers
67 views

How to do a grep on remote machine and print out the line which contains those words?

I have few logs files in my machineB under this directory /opt/ptd/Logs/ as shown below - My logs files are pretty big. david@machineB:/opt/ptd/Logs$ ls -lt -rw-r--r-- 1 david david 49651720 Oct 11 ...
5
votes
1answer
39 views

Representing/quoting NUL on the command line

Can \0 be used on the command line? Background For testing corner cases in GNU Parallel I was curious whether all characters were correctly quoted on the command line. Most of them are: perl -e ...
0
votes
0answers
63 views

BASH-3 update: how to revert / undo the changes?

I am using Mint 17, 64-bit with Cinnamon. I recently updated Bash and following the update mint drivers are missing and mint is not working. So I want revert the changes. How can I do it? For ...
1
vote
2answers
132 views

Motion start sequence - shell script modification

I've tried to modify this script to start Motion using the following libraries. I start the script by entering the following command into terminal: sudo /etc/init.d/motion start Which Gives: ...
1
vote
1answer
64 views

What are the types of ~, ~-, ~+, *? [duplicate]

If I am correct, pwd is a command, PWD is a variable('s name), and - in cd - is an operand. What are the types of ~, ~-, ~+, * when they mean $HOME, the previous visited dir, the current dir, and the ...
0
votes
0answers
30 views

What does && mean in cd “$OLDPWD” && pwd? [duplicate]

What does && mean in cd "$OLDPWD" && pwd? Is it used to connect two commands and run them sequentially in some way? Is it a logical operator of bash?
0
votes
1answer
65 views

shell script edited on windows displays unexpected error message [duplicate]

I am having some trouble running a script to ssh to a remote server. If I simply ssh from the command line I have no trouble reaching the server, but when I run a script to do this I get an error, ...
3
votes
2answers
251 views

How does exec bash builtin work internally?

From this link I get the following about exec bash builtin command: If command is supplied, it replaces the shell without creating a new process. How does it exactly replace the shell (i.e. ...
4
votes
1answer
83 views

How can I create an alias that passes additional arguments?

I have an executable that I use often: /dir1/dir2/dir3/dir4/executable argv[1] argv[2] argv[3] I know that I can set an alias for the executable: alias myexecutable = ...
-2
votes
1answer
97 views

How can I update BASH [duplicate]

How can I update BASH? I noticed that there are version 4.2.45 env x='() { :;}; echo vulnerable' bash -c "echo this is a test" this is a test cat /etc/redhat-release CentOS release 5.11 (Final) rpm ...
0
votes
3answers
29 views

Redirect stderr and stdout to another file descriptor

exec 6>&1 will copy file descriptor 1 onto 6. But how can I copy both stderr and stdout (1 and 2)to file descriptor 6 ?
3
votes
3answers
318 views

Better way to run single for loop instead of two for loops

This works but the way I did this is kind of silly. Is there a better way to do this? for e in $(ipcs | awk '{print $2}'); do [[ "$e" = "Semaphore" ]] && break echo $e ipcrm shm ...
4
votes
3answers
250 views

How do I auto complete a command from the command history? [duplicate]

Is there a key combination for bash to auto compete a command from the history? In ipython and matlab for example this is achieved by pressing up arrow after typing a few characters.
3
votes
1answer
120 views

How can I run a bash variable as a command exactly without additional quotation?

I'm trying to make a script which needs to save a command to be run as a string. The string in question needs to contain quotes, and when attempting to execute it bash adds additional quotation ...
-1
votes
1answer
51 views

syntax error: unexpected end of the file

#!/bin/bash #organization: Seneca College #Purpose: Validate a date #Usage: chkdate year month day # year=$1; month=$2; day=$3; extra=$4 if [[ "$year" == "" || "$month" == "" || "$day" == "" ]]; then ...
-1
votes
1answer
43 views

how to select multiple exit

I'm new to bash scripting and I don't understand what's wrong with this specific part of my script. im trying to select all the exit that have in my script. and trying to put in conditon that if all ...
3
votes
3answers
132 views

Can you source a “here document”?

Let's say I have a bash script that acts as a config file for another bash script: config.sh: verbose=yes echo "Malicious code!" name=test script.sh: source config.sh echo "After sourcing: ...
1
vote
1answer
119 views

Shellshock - not vulnerable with bash version 4.1?

We have several Amazon servers. It has bash version 4.1.2. Kaspersky claims that all bash versions up to 4.3 are unsafe. When I do this test... env x='() { :;}; echo vulnerable' bash -c 'echo hello' ...
2
votes
2answers
100 views

Bash not equal string comparison

Why does this cause an infinite loop? #!/bin/bash while [[ "$(ipcs | awk '{print $2}')" != "Semaphore" ]]; do #Gonna get rid of the echo after working echo "$(ipcs | awk '{print $2}')" #I wanna ...
2
votes
0answers
49 views

Why do some processes pass on their cpu usage to another process when it ends?

I have wondered this for a while. For example, lets say process1 is a process that uses a lot of cpu power, like 90%. Its a video game. Then i have process2 which uses 10-12% cpu. Its a web browser. ...
1
vote
1answer
75 views

Why is variable assignment preceding command ignored? [duplicate]

The bash 4.1 manpage states (emphasis added)... Simple Commands A simple command is a sequence of optional variable assignments followed by blank-separated words and redirections, and ...
0
votes
1answer
117 views

Bash if statement [: missing `]' error [duplicate]

I am having trouble with bash. I am trying to put a command in an if statement and then compare it to a string. This works perfectly. echo $(ipcs | grep Shared | awk '{print $2}') When I put it in ...
2
votes
1answer
66 views

Copy multiple files and create the target directories at the same time?

I read How can I copy a file and create the target directories at the same time? But the solution there only works if you want to copy one file. How would I copy multiple files into a directory, ...
1
vote
3answers
136 views

bash script that reads user input and uses “cal” command to validate dates

I want to write a script that reads my input (for example if my script is called "check", then I would type "check 9 4 1993" and that input would go through the cal command and will check through the ...