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

17
votes
3answers
181 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
73 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
675 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 ...
-1
votes
0answers
19 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
51 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
23 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
38 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
44 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
59 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
36 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
53 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
112 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: ...
0
votes
1answer
60 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
60 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
238 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
78 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
84 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
22 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
316 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
240 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
111 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
44 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
39 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
122 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
105 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
82 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
44 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
67 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
102 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
64 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
121 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 ...
2
votes
0answers
39 views

bash syntax error near unexpected token `(' - but everything looks like it should work [duplicate]

I'm trying to write a bash script which will copy a bunch of files and directories from a directory, omitting a couple but taking everything else. I have got a command that does this and works from ...
4
votes
2answers
584 views

How do I delete all of a set of files in a random order?

I have a set of files, all that are named with the convention file_[number]_[abcd].bin (where [number] is a number in the range 0-size of drive in MB). i.e there is file_0_a.bin, file_0_b.bin, ...
0
votes
1answer
23 views

Shell script permission denied despite +x flag

This is an odd one, it only happens on one server (shared hosting, so I have limited access to configuration and logs), but I can't wrap my head around it. I have a shell script which runs some app's ...
4
votes
3answers
315 views

How to check whether a process is daemon or not?

I have written a small daemon that starts at the boot time and does all the things perfectly like writing in the log file. But I want to know, how can we check whether that process is daemon or not? ...
1
vote
2answers
86 views

bash question about if and then [duplicate]

I'm writing this in my script. It has other parts but I'm getting stuck on this part only. if [[$# == $year $month $day ]] ; then cal $day $month $year fi When I run this it give me this msg: ...
0
votes
1answer
50 views

how to write this if command?

my script name is 1. when i type in "1 2012 12 12". it shows current date calendar and when i enter a invaild date like "1 2323232" cal gives me a error so how could i put that in if loop that if it ...
5
votes
2answers
379 views

Did the shellshock bash fix break basic command line tools like echo and cat? [duplicate]

I used to be able to do things like: X=123 cat <<EOF X is $X EOF or even simpler: X=123 echo $X The first one still seems to work on Mac OS X after install the bash fix, however neither ...
-1
votes
1answer
37 views

how to create a dynamic password thats between 8 and 16 characters [duplicate]

This is my password generator and it generates 8 characters and shuffles them. But i need to make it dynamic length. How would i go about doing that. So the output would be different length between 8 ...
0
votes
1answer
39 views

use EOF in a one-liner?

I have a simple script that executes commands on remote host using ssh and EOF I was trying to do it with a one-liner at command line but I couldn't figure out how to do the EOF outside of a script. ...
1
vote
0answers
46 views

export -f in .bashrc after upgrade to bash 4.3.30 kills builtins?

I recently upgraded my bash (Mac OS X 10.6.8) from 3.2.48(1) to 4.3.30(1) via macports, and while the install seems to have gone smoothly, the two spots in my ~/.bashrc where I had export -f myfunc; ...
0
votes
0answers
49 views

Can call login command from terminal

I want to create a user using useradd from root in my terminal window, after it I call passwd to set user's password. So I cant call login username because when I call it from terminal it closes ...
0
votes
1answer
46 views

generate password that is random length between 8 - 16 ( i have the generator but its not dynamic) [duplicate]

This is my password generator and it generates 8 characters and shuffles them. But i need to make it dynamic length. How would i go about doing that. So the output would be different length between 8 ...
2
votes
4answers
191 views

Creating symbolic link recursively

I essentially want to run this command... ln -s /opt/gitlab/embedded/service/gitlab-shell/hooks/ /var/opt/gitlab/git-data/repositories/web/*/hooks This would create a symbolic link in all folders ...
2
votes
3answers
62 views

How to nest quotes in bash commands

I want to test the result of this command: dmesg | grep "Firmware patch 1563" Therefore, I try to write something like this: if [ "`dmesg | grep "Firmware patch 1563`" == "" ] But it doesn't ...
1
vote
1answer
57 views

Replace pattern in file with pattern in second file

I want to replace part of a file's data, with data from another file. Suppose file1 has data as is written below and file2 has some data I want to store and replace file1 data from file2 from ...
0
votes
0answers
34 views

patch bash at sunos5.7

Refer:shellshock solution for nexenta/solaris post for shellshock solution may I confirm the command is method1: /usr/local/bin/curl \ https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patchs/bash32-001 ...
4
votes
2answers
82 views

Where do bash completion functions come from?

I have a Raspberry Pi running Raspbian (Debian Wheezy). I entered set in a terminal and was surprised by the long list. This seems to be almost entirely git functions — ~3700 lines of them. ...