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
0answers
90 views

Themed Tabs in Gnome Terminal

I've created a custom desktop session which upon login presents the user with a full screen gnome-terminal session. The idea is to have a TTY-like session but with the added advantages provided by X ...
0
votes
1answer
310 views

Bash script installing within multiple directories [closed]

I am attempting to write a bash script that will install rbenv from beginning to end. I am on a Mac for interest sake. But there are some things that are not working mainly i am changing the ...
3
votes
1answer
92 views

Specific string hangs [, [[

While fuzz testing I've found that it's possible, by defining var=$'\365\\' , to make both of the following commands (used to remove everything up to the last newline) hang indefinitely, consuming ...
3
votes
3answers
1k views

Return status of `cd` is always 0

I am executing following command. cd dirname; echo $? This always return 0 whether of not cd is successful. This is giving me incredible headache. How to check if cd was successful without reading ...
6
votes
5answers
1k views

Rename file in another directory without repeating path [duplicate]

I often need to make a small change to a file nested several directories below my current working directory. Since it's only one file, and globbing/scripting would be overkill, I make the change ...
0
votes
4answers
2k views

echo a loop with variables command

I have several lists and want to run some commands over them. As lists are long I want to run those commands parallel to each other, hence using nohup. For every item I tried to echo a loop that ...
4
votes
4answers
191 views

echoing symbols in terminal/bash

Why am I not able to use "!" when trying to echo a message in terminal? For example: echo -e "Hello\nWorld!" bash returns the following command: bash !: event not found
1
vote
1answer
390 views

Bash scripting rsync puzzler

Frustrating. The script below work for the first two targets, but not the second. #!bin/bash ... backitup () { Todaysdate=`date "+%Y-%m-%dT%H_%M_%S"` Sourcedir=$1 Destination=$2 Username=$(echo ...
53
votes
3answers
157k views

How to append multiple lines to a file with bash

I am writing a bash script to look for a file if it doesn't exist then create it and append this to it: Host localhost ForwardAgent yes So "line then new line 'tab' then text" I think its a ...
4
votes
1answer
2k views

Bash console progress dialog with command output

I have dialog installed, where I would like to have a nice progress dialog, like this: +-------[ title ]--------+ | | | +-[ console output ]-+ | | | output line11 ^ | | | ...
0
votes
3answers
487 views

Inserting the results of a for loop into an html file - BASH

I have a script that takes the results of a command and puts them into a html code. Here's what I have so far... #!/bin/bash list_dir=`ls -t downloads/` for i in $list_dir do #---- # echo ...
1
vote
2answers
520 views

Bash variable into html

I have a script that gets the filenames in a folder and creates HTML link to them on my homepage. Here is the script: #!/bin/bash list_dir=`ls -t /path/to/dir/` for i in $list_dir do echo ...
9
votes
2answers
619 views

How do I stop bash from syntax checking sourced files?

I have the following code in a file that is sourced by both zsh and bash. if test $SHELLNAME = zsh ; then lss() { l -l ${1:-.}/*(s,S,t); } laf() { l ${1:-.}/.*(.); } lad() { l -d ...
3
votes
3answers
173 views

Persistent shell arguments

I often find myself running a series of commands on a single set of arguments. For example: $ nmap -Pn -sS 192.168.1.5 $ ssh 192.168.1.5 $ curl 192.168.1.5 $ wget -r 192.168.1.5 This can be sped ...
5
votes
4answers
9k views

What is the `editor` command in bash?

I was looking for a command that would hopefully open the current user's favourite text editor, because I am writing out some instructions with commands in a blog. I was expecting a command like edit, ...
6
votes
3answers
1k views

Custom autocomplete: deal with spaces in filenames

A bit of context, this question is a follow-up of this one: Bash remote autocompletion : change the 'starting' directory Anyway, I'm writing my custom autocompletion bash script: I want the ...
3
votes
2answers
576 views

Passing quotes and full strings to bash -c or zsh -c

When I am in Perl and I call system(some_command), this invokes some_command on /bin/sh. I would like it instead to run some_command in another shell such as bash or zsh. One way of running ...
2
votes
3answers
229 views

bash script selecting the last path variable

Hey all i am writing my first bash script. and i am making it install all the repos i have on github. warpInLocations=("git@github.com:acc/toolkit.git" "git@github.com:acc/sms.git" ...
-2
votes
1answer
282 views

bash script user promt for prefered directory

hey all i am attempting my first bash script. so i would like to prompt the user to find out where they would like a cloned repo to be saved currently i am assigning it like this ...
2
votes
3answers
2k views

How to automate connecting to multiple network devices, running a command and saving the output to a file?

I have to run a command on around 1000 network devices and save the output to a file. In a file I have a list of all the network device names that have to be connected to using SSH. I then have to run ...
1
vote
3answers
1k views

How to rename pattern in one file to another over several directories recursively

I have several directories through which I want to recursively iterate over and change the file name of *.GEOT14246.* to *.GEOT15000.* Is there a one liner on the bash script to do this ...
0
votes
1answer
2k views

Identify Tasks/Process which are 7 days old in linux

How can I identify the processes running since 7 days in Linux?
0
votes
2answers
3k views

Creating an email that can trigger a script

I have a CentOS 6.3 server. I would like to create an email address like, for example, list@myserver.com that will be a special kind of email that will trigger a script. For example: suppose I mail ...
11
votes
4answers
2k views

Is there a way to refer to multiple files in a directory without retyping the whole path? [duplicate]

In a bash shell, when I have to remove multiple files in the same directory, I currently need to do something like this: rm /some/path/file1 /some/path/file2 Is there a shorter way to write this so ...
1
vote
2answers
611 views

How to get name of Display Manager on Linux? [duplicate]

I want to see Display Manager name (Gnome, KDE etc.) via python or bash script. Is there any command for it as uname? (I try fedora and Debian)
9
votes
4answers
40k views

BASH: launch background process and check when it ends

How can I launch a process in background and check when it ends within a bash script? My idea is a script like this: launch backgroundprocess & while [ Process is running ];do echo "PROCESS ...
2
votes
3answers
3k views

Easy way to parse syslog date format

I'd like to write a script that analyses the last week's syslog. But my syslog logs in a stupid date format, e.g. "May 22". If it logged as 2013-05-22, this task would be trivial. Is there a way ...
0
votes
0answers
100 views

unexpected bash behaviour after console login (openSUSE)

I'm trying to install a Linux OS on the computer I use as a home server, because I liked "Raspbian" so much on my Raspberry Pi. I created a custom linux using openSUSE Studio, that's just text based ...
4
votes
2answers
847 views

How do I let bash autocomplete wildcards?

If I have directory containing the files foo.bar.a.cat foo.bar.a.hat and I type ls f+TAB the bash shell autocompletes to ls foo.bar.a.. If I type ls *bar*+ TAB I would like it to autocomplete to ...
5
votes
3answers
969 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?
20
votes
3answers
6k views

Can't indent heredoc to match nesting's indent

If there's a "First World Problems" for scripting, this would be it. I have the following code in a script I'm updating: if [ $diffLines -eq 1 ]; then dateLastChanged=$(stat --format '%y' ...
1
vote
1answer
52 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
2k 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 ...
6
votes
2answers
10k 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 ...
3
votes
2answers
14k views

Colorful ssh banner

I would like to colorize my ssh banner. I know 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 some ASCII art in the banner ...
3
votes
1answer
102 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 ...
4
votes
4answers
12k views

Perform floating point arithmetic in shell script variable definitions [duplicate]

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 ...
50
votes
5answers
43k 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 ...
5
votes
4answers
764 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
198 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 ...
4
votes
1answer
1k 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 ...
3
votes
1answer
693 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
714 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 ...
16
votes
6answers
30k 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 ...
2
votes
1answer
1k 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. ...
5
votes
2answers
7k views

Writing starting from a certain line number in a text file

In a bash script I want to write some lines to a text file, but this file has already been used before and there are texts in it. So I want to echo some additional text in it, starting from a certain ...
3
votes
5answers
806 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
457 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 ...
1
vote
1answer
3k 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, i.e. not the last one, but the one before the last one. I tried kill $$(($! -1)) but ...
6
votes
1answer
1k 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 minute. i.e.: the command will run the music.mp3 starting from the minute 1. I am able to run a music with rhythmbox ...