Bash is the shell from the GNU project. It is the standard shell on many Linux distributions and often available on other *NIXes.

learn more… | top users | synonyms

5
votes
2answers
67 views

Walking through files in directory randomly

How to change for track in *.mp3; do so that all .mp3 files in the current directory are walked through but in a random way?
3
votes
1answer
36 views

Can't indent heredoc to match nesting's indent

If there's a "First World Problems" for scripting, this would be it. Mainly asking because I feel like I should know how to get around it if I need to. I have the following code in a script I'm ...
1
vote
1answer
39 views

bash_completion

I have a simple script, which creates a symlink IP_address -> config_file (used for pxe boot). My script is called like this: lnpxe CONFIG HOSTNAME where CONFIG is one of my config files stored in ...
1
vote
3answers
68 views

Setting file permissions in bash script

This script is not working the way I thought it would .I though it would find all the scripts that have every one rwx permissions changed to the permissions of xx5 #!/bin/bash # the / makes find ...
2
votes
2answers
41 views

rsync certain files, excluding the rest, ignoring .svn/ directory, recursively

I'm using rsync to copy some files from a share to another. Recursively, I need to: Delete files at destination that were removed from the origin Only sync php and js files Exclude every other file ...
1
vote
2answers
64 views

Colorful ssh banner

I would like to colorize my ssh banner. I now I can perform it like so : In /etc/profile I can put echo -e "\e[1;31m Colorful text" echo -e "\e[0m Reset" But I have an ASCII art in the banner ...
3
votes
1answer
65 views

Where to put scripts only to be called by another script?

I've written a basic command line application composed of multiple bash scripts. One of these is intended to be run by any user of the computer, so I understand the correct location for this would be ...
2
votes
4answers
56 views

Perform floating point arithmetic in shell script variable definitions

I understand bash and some other interpreters only perform arithmetic for integers. In the following for loop, how can I accomplish this? I've read that bc can be used but am not sure how to use bc ...
10
votes
3answers
424 views

What is the difference between “sort -u” and “sort | uniq”?

Everywhere I see someone needing to get a sorted, unique list, they always pipe to sort | uniq. I've never seen any examples where someone uses sort -u instead. Why not? What's the difference, and why ...
4
votes
4answers
105 views

sed how to substitute when string has “http://” in it?

I have a file xx that has the following contents: @base_url = "http://dmstaffing-stage.herokuapp.com/" I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
3
votes
0answers
55 views

Fork vs. thread system time [closed]

I got the following logs: Program 1: Taken from a program executed 64 fork calls: real 0m0.023s user 0m0.068s sys 0m0.008s Program 2: Taken from a program executed 64 thread calls: real 0m0.613s ...
3
votes
1answer
55 views

Tab completion doesn't work for arguments when command is an alias

I have an alias, ee, defined for my favorite editor, mg. When I do something like mg fo and then hit tab, if a file foo exists, I get tab completion to: mg foo On most systems I use (e.g., all ...
2
votes
1answer
36 views

Bash remote autocompletion : change the 'starting' directory

I'm regularly downloading files from a remote server, always from the same directory. So I wrote a custom function that I put in my bashrc: download_from_myserver () { for file in "$@" do ...
0
votes
1answer
30 views

Opera, Firefox has no kiosk option like Chrome gives it openly?

While using Chrome kiosk mode, i have problem with openbox desktop, its not doing correct for some javascript rendering. So i wanted to test opera and firefox but both does not support kiosk at all ...
0
votes
0answers
16 views

keyserver timed out when trying to add a GPG public key

I am trying to add a public key for installing a program with CPG. But i am pretty new to this but every command i found gave me the same error: gpg --keyserver keyserver.ubuntu.com --recv-keys ...
1
vote
1answer
35 views

How to write a script to read wifi SSID and password from USB drive at boot up and auto logon to wifi network

I have an embedded system that is running Debian. I want to be able to provide wifi network SSID and password information via a USB thumb drive. That way I can easily deploy it to any wifi network. ...
1
vote
2answers
66 views

Writing starting from a certain line number in a text file

In bash script i want to write some lines on a text file , but this file is already used before and there are texts in it ,so i want to echo some additional text ut starting from a certain line number ...
2
votes
4answers
41 views

How to set proper monitoring of my services in a automated way? So that if one crash it auto on the fly restarts?

How can i setup monitoring to my system services? Either using automated script which scan every moment, if httpd, mysqld, and my custom daemon is running or not, if not running it will automatically ...
4
votes
1answer
78 views

Passing a stream to a bash function

I need to create a bash function that I can pass a stream to NOT A FILE. Here is the function: ff() { cat /etc/group | fgrep -f "$1" ;} When I run it like so: ff <( echo some_user ) I get an ...
0
votes
1answer
54 views

How to kill the (last - 1) PID with bash

I know how to kill the last process with kill $! However I would like to kill the last - 1 process, ie not the last one, but the one before the last one. I tried kill $$(($! -1)) but it ...
3
votes
1answer
29 views

Start a song from a specific time in rhythmbox using command line

I would like to start a song from my terminal, starting from the first min. i.e.: the command will run the music.mp3 starting from the minute 1. I am able to run a music with rhythmbox music.mp3 ...
0
votes
2answers
65 views

How to create as many variables as needed from shell script(bash)?

I'm making a script for monitoring some user processes with Upstart but, since its for the company I work for, they asked me to do it generic...how's so? Well, the number of processes being monitored ...
0
votes
0answers
48 views

Using an alias or function to run process in background, with dot files [closed]

Drews-MacBook-Pro:5493040 drewgross$ function s() { subl "$@" & } Drews-MacBook-Pro:5493040 drewgross$ s .profile [1] 1268 -bash: .profile: command not found Drews-MacBook-Pro:5493040 drewgross$ ...
13
votes
1answer
261 views

Can bash case statements cascade?

I'm trying to do something like this: case $level in 3) echo "Level Three" 2) echo "Level Two" 1) echo "Level one" ;; esac where if $level = 3, it ...
4
votes
4answers
111 views

Can I write the output the of time difference command to a file?

Can I write the output of the time difference command to a file? For example, I tried: $ time foo.sh > bar.txt But it only gives the output of foo.sh to bar.txt.
3
votes
5answers
65 views

bash getopts, short options only, all require values, own validation

I'm trying to build up a shell script that accepts various options and getopts seems like a good solution as it can handle the variable ordering of the options and arguments (I think!). I'll only be ...
2
votes
4answers
75 views

How can I uncompress gz files in random directories and store the decompressed files in those same directories?

CentOS 5.9 I've got a server with a foo.ext.gz file located in a variety of random directories. Example: /opt/fooapp/foosubdirectory/foo_randomnumber/blah/blah/foo.ext.gz ...
9
votes
3answers
324 views

Why does “$(( ~33 ))” produce -34?

$ echo $(( 255 )) 255 $ echo $(( 33 )) 33 $ echo $(( ~33 )) -34 $ echo $(( ~255 )) -256 $ and my kernel is: $ uname -a Linux HOSTNAME 3.2.0-40-generic-pae #64-Ubuntu SMP Mon Mar 25 21:44:41 UTC ...
2
votes
1answer
90 views

Why does cd default to ~?

When you type cd, it basically does the same thing as cd ~. Why? I'm wondering if it's just a hard-coded behavior or if bash is expanding the command or something.
2
votes
2answers
51 views

Share background jobs between shells

I use Screen with a lot (more than 10) of local Bash sessions inside. I send some processes (like vi file) to the background and switch between sessions very often and sometimes it's very annoying to ...
1
vote
2answers
60 views

Split using sed

I have to split [X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000 at the pipes and output those line whose 2nd and 3rd argument are different.
0
votes
1answer
54 views

When running a terminal, I get the default bash prompt

Whenever I run a terminal in Linux (Centos), my console line starts with: bash-4.1$ During the Centos installation, I created a user 'mark'. Later on that day, I needed to change the name to 'john' ...
21
votes
7answers
2k views

why does ls -d also list files, and where is it documented?

when specifying ls --directory a* it should list only directories starting with a* BUT it lists files AND directories starting with a Questions: where might I find some documentation on this, ...
4
votes
3answers
133 views

How do I quickly move the cursor to the end in bash in vi mode?

I don't know why but when I'm in insert mode and I move left from the last cursor position (the empty spot to the right of the last character), then I can't go back to that position anyomre. Instead ...
3
votes
2answers
55 views

Wait for a X window to appear/disappear (in a sane way)

Inside a shell script, I need to wait for a window that has a string on its title to appear, do some action, and then wait for it to disappear, and do some other action. Until yesterday, I had this ...
12
votes
6answers
434 views

Is it common to split larger script into multiple scripts and source them in the main script?

At the moment I'm developing a larger Bash script (it's an Open Source project of mine) and it's starting to become a mess. I've split up logic into functions, use local variables where I can and have ...
1
vote
1answer
41 views

how to locally redefine 'command_not_found_handle'?

I'd like to make a particular bash script failfast when it cannot find a command, while retaining globally the usual friendly command_not_found behavior. E.g., if I save the following to /tmp/foo.sh, ...
2
votes
1answer
34 views

process continous output of synclient

I am using synclient to track the position of finger on the touchpad. I use the following command. synclient -m 100 | awk '{print $2,$3}' This command gives the 'x' and 'y' co-ordinate on the ...
-1
votes
4answers
77 views

Ending Process Infinite Loop Input Redirection

Edit: I realized that the program I was trying to run had an infinite loop after scanning all my input. Then just prints out infinitely so it'll never read the EOF. It'll read the last input then go ...
2
votes
2answers
60 views

Including sub-parameters in help options to execute wisely without getopt or getopts?

I am writing a script which can choose a file and print specific content. For example, san#./script.sh Expected Usage : ./script.sh --file1 --dns (Here it checks for file1, search for dns name and ...
1
vote
1answer
58 views

How to open process substituted file from php?

Here's what I tried to do myself: $ type 1.sh #!/bin/bash -eu php -r 'var_dump(file_get_contents($_SERVER["argv"][1]));' -- <(echo 1) $ ./1.sh PHP Warning: file_get_contents(/dev/fd/63): failed ...
3
votes
2answers
61 views

Setuid bit seems to have no effect on bash

I was experimenting with the security of my system and noticed something strange: setting the setuid bit on a copy of bash located at /usr/bin/bash-test seemed to have no effect. When I ran an ...
0
votes
1answer
47 views

Can I redirect output to a log file and background a process at the same time?

Can I redirect output to a log file and background a process at the same time? In other words, can I do something like this? nohup java -jar myProgram.jar 2>$1 > output.log & Or, is that ...
4
votes
6answers
86 views

Getting two fields from same line together

I've got a situation where I've got several lines, and I need two different fields out of each of them. To be specific, I have a list of references in a bibliography and I want to get the last name ...
1
vote
1answer
72 views

what's wrong with embedding php scripts inside bash ones?

I was trying to use php inside bash script, but I came across several problems. My first try failed with error about bash not being able to find end of here-document. The minimal version that still ...
5
votes
4answers
141 views

Hybrid code in shell scripts. Sharing variables

This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
4
votes
2answers
97 views

Wrap command in the prompt

Is it possible to insert a separator after the command in a prompt? This is an example: ~/Desktop: ls -al ------------------------------------- total 80 drwx------+ 6 eddie staff 204B Apr 29 ...
0
votes
1answer
24 views

Watch goes blank on refresh [duplicate]

I'm running the following command in watch. Works for the first one but subsequent ones go blank watch diff <(pacman -Q) <(ssh kate "pacman -Q")
2
votes
1answer
81 views

bash script - supervisor program

I have to write a shell-script that have to do the following tasks: -in every 5 seconds it saves:     -how many users are using joe and/or vi;     -if ...
3
votes
1answer
45 views

Custom key bindings for vi shell mode, ie, “set -o vi”?

I just discovered the wonders of set -o vi, and am curious if it is possible to customize this vi shell mode in some of the same ways you can customized vi or vim? For example, create a custom key ...

1 2 3 4 5 43