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

2
votes
2answers
295 views

perl regex replacing globally when global not selected

I'm using Ubuntu 11.04 and wrote a small script that searches within text files for certain "tokens" and replaces with some a prewritten snippet from a template file of the same name. The text files ...
13
votes
3answers
2k views

How to delete part of a path in an interactive shell?

Is there a shortcut in bash and zsh to delete one component of a path? For example, if I type ls ~/local/color/, and the cursor is at the end of line, is there a shortcut to delete the color/ at the ...
1
vote
1answer
341 views

root shell isn't using --color=auto

Does anyone know why the root user doesn't have a colour coded shell? It would seem to me the one person who navigates the file system the most is the root user, s/he would benefit most from the ...
1
vote
1answer
489 views

Why does curl fail while using this export?

I'm doing some stuff with Facebooks FQL at the moment, and I'm using curl on the command line to test some of the responses of it. I'm also using export to keep the params seperated for easy editing. ...
9
votes
2answers
2k views

Piping for loop output prevents local variable modification

I'm trying to write a simple bash function that takes, as its arguments, a number of files and/or directories. It should: Fully qualify the filenames. Sort them. Remove duplicates. Print all that ...
6
votes
1answer
5k views

Running a bash script from a zsh shell

I'm having problems running a bash script on zsh. The script is similar to the one below and is supposed to run under bash: #!/bin/bash echo "<235234>" | egrep -oe [0-9]+ However, my shell ...
0
votes
1answer
150 views

how will I make interactive login

I'm having trouble in making script with interactive login. I have made one but it doesn't ask the login, it automatically log in when i run the script. i just need the output like this: please ...
4
votes
2answers
263 views

Understanding quotes in a bash conditional instruction

My friend is messing around with Bash scripts and he wanted me to take a look at them (he had another friend do it for him). One of the commands is if [ "`pidof transmmission-gtk`"=0 ]; what ...
2
votes
2answers
823 views

How do I install multiple java command-line programs?

I have a bunch of java command-line programs I've written and would like to install for all users. Building with NetBeans, I get a /dist directory which contains myprog1.jar and a /libs directory ...
9
votes
1answer
684 views

How do you omit “./” when running scripts on current directory

On some tutorials over the internet they can run a script on the current directory without doing: ./script How do you omit this? I am using CentOS 5.6 x64. I want to run it this way script
3
votes
2answers
3k views

From shell, killing a process if wallclock runtime exceeds some predetermined value

I want to start a process from a shell script, allow it to interact with the user (so I cannot just background it, grab the PID, launch sleep followed by sanity checks and kill), but if it is still ...
4
votes
2answers
381 views

Saving tab completion possibilities to a file

Instead of displaying all possibilities on terminal screen, as in: $ ls /etc/<TAB> Display all 230 possibilities? (y or n) I want to save all possibilities to a file. ls /etc/ > file.txt ...
1
vote
1answer
456 views

Changing file extensions [duplicate]

Possible Duplicate: Renaming multiple files (changing extension) Suppose I have a bunch of files with the extension .x and I want to change them so that they have the extension .y. I know $ ...
5
votes
3answers
4k views

Print shell arguments in reverse order

I am a bit stuck. My task is to print the arguments to my script in reverse order except the third and fourth. What I have is this code: #!/bin/bash i=$# for arg in "$@" do case $i in ...
0
votes
1answer
293 views

Non printing characters

I would love to get the mappings to work for keyboard shortcuts shown here http://ascii-table.com/ansi-escape-sequences.php I have the hang of color but for some reason nothing else seems to work!
7
votes
2answers
4k views

Can I automate tar's multi-volume-feature?

Ok, so I've just had a read through this page after a way to improve my current backup solution on my Debian server. Tar seems to be offering a quite nice multi-volume feature, although when I try it ...
20
votes
1answer
3k views

Execute bash scripts on entering a directory

What is the best way to execute a script when entering into a directory? When I move into a new directory I would like bash to execute the projectSettings.bash script much like RVM does.
2
votes
2answers
2k views

How do I cause a watchdog reset of my embedded Linux device

Is there a command like vi > out vi | out That I could use to cause a watchdog reset of my embedded linux device?
8
votes
1answer
3k views

Alias a command to run in the background

I'd like a keyboard shortcut to work as so: > e foo.txt to expand as > emacs foo.txt & It's simple to use alias e=emacs, but how do I insert the & after the filename? I realize it ...
3
votes
2answers
339 views

How can I “cache” a variable in Bash?

I have a bash script which is run every 10m by cron. The script performs an expensive calculation for some value (say variable x=value). I need to "cache" this value for 2-3 hours. What are possible ...
3
votes
3answers
3k views

How to pass a string parameter on bash function?

I have this code that does work: get_parameter () { echo "$query" | sed -n 's/^.*name=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" } But I want to replace the "name" with the parameter that I pass ...
1
vote
1answer
163 views

How does this bash function work?

I'm looking at this short example, and I don't see how this function works: function EXT_COLOR () { echo -ne "\[\033[38;5;$1m\]"; } AFAIK -ne stands for not equal. What are we comparing here? I ...
5
votes
2answers
1k views

Why doesn't “rm *” work when there are files that begin with a hyphen?

from: http://seclists.org/fulldisclosure/2011/Sep/190 [USER@MACHINE ~] mkdir ejha [USER@MACHINE ~] cd ejha/ [USER@MACHINE ~/ejha] touch ize [USER@MACHINE ~/ejha] touch -- -f -i [USER@MACHINE ...
5
votes
3answers
894 views

How can I reset all the bind keys in my Bash?

I bound some keys by mistake, and they don't work any more, such as HOME, END, UP, DOWN, LEFT, RIGHT. Is there a way to reset all the bound keys to their original state?
5
votes
3answers
1k views

How should I add users non-interactively?

I have a set of users I need to add to a new system as part of a BASH script that preps my server. How can I non-interactively add the user, create their home directory, set the group, and enter a ...
3
votes
5answers
878 views

How can I test whether connection to the given host/port is established in Bash?

Currently I'm using netstat for this: if netstat -an | grep ESTABLISHED | grep $address:$port > /dev/null; then # command fi Is there a more elegant solution?
7
votes
2answers
957 views

sharing or synchronizing history between Zsh and Bash

I often find myself switching between Bash and Zsh, and using the history search functionality to recover a command. However, since Bash and Zsh have different history files, I often find that the ...
3
votes
1answer
2k views

Showing GNU screen session name and window title in shell prompt

Is there a way to present the GNU Screen session name and window title in the prompt of the shell (let us say, the Bash prompt defined by PS1)?
2
votes
2answers
467 views

Script to prepend the files path to a file recursively

I work as a grader and files submitted to me end up in a folder named with the student's name which is itself inside a specific folder on my linux share. Currently I go through each source file and ...
9
votes
5answers
14k views

Is there a way to set the size of the history list in bash to more than 5000 lines?

No matter how much I set the HISTSIZE environment variable to be larger than 5000, when printing the history list with the history builtin, it prints only the last 5000 commands. I need that because I ...
6
votes
1answer
1k views

Customizing bash shell: Bold/color the command

There are a number of tutorials/posts online (e.g. http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/) about how to customize your prompt in bash by ...
2
votes
1answer
149 views

Need to find a cronjob

I have a problem, some user ,and I'm not sure who, on one of my servers wrote a cronjob that executes every night at midnight. The cronjob creates a sql dump of a database which is then grabbed by ...
66
votes
13answers
94k views

How can I resolve a hostname to an IP address in a Bash script?

What's the most concise way to resolve a hostname to an IP address in a Bash script? I'm using Arch Linux.
4
votes
4answers
1k views

Which stream does Bash write its prompt to?

I am trying to redirect all output from bash (prompt, user input, results) to a file Example: /bin/bash > file.txt 2>&1 I thought that would work, but I'm not getting the prompt. Can ...
4
votes
1answer
677 views

How to stop Bash appending history

I am having a lot of trouble setting up the terminal history of Bash the way I want. I would like to have no duplicate entries and if I enter a command I want it saved and the duplicates above ...
2
votes
1answer
1k views

Load my .profile for bash in Emacs terminal buffer? (multi-term mode)

I've got multi-term mode (derived from ansi-term) with bash started in Emacs 23.3, which is a terminal emulator running in Emacs. However, I noticed that it did not load my user profile, including ...
3
votes
2answers
303 views

Using `select` command to print menu in Linux

OS - Linux 64-bit I am trying to implement a simple menu using select command. The script (for testing purposes) is as follows #!/bin/bash echo "*******************" PS3='Select an option and press ...
7
votes
1answer
457 views

Note-taking and outlining using Vi: On startup, highlight tags and display tags in a preview window [duplicate]

I am using vi as a note-taking and outlining tool and therefore I thought that this stackexchange site would be appropriate to ask this question. I am constructing the "tags" file by myself. What I ...
0
votes
2answers
185 views

How to put Mysql path in bash profile on MacBook Pro 10.6.8

I want to put a mysql path into the bash profile of my macbook pro. How do I access the bash file and then make it visible in the finder so I can open it with a text editor and put in the path?
1
vote
2answers
599 views

Unix read -p command causes bash error, how do I fix it?

I'm trying to prompt the user for a comment function comment { if [ ! $1 ] then read -p "enter checkin comment &lt; " COMMENT; else export COMMENT="$1" fi if [ ! $COMMENT ] ...
3
votes
3answers
5k views

Is there a way to write a script to do ftp login so I don't have to type things over and over again?

I am recently working extensively with a remote system via ftp connection, since the session time is so short that I have to re-login quite often when I finish my work on my local machine, so I need a ...
3
votes
1answer
698 views

TinyCore Linux & RVM

I'm running TinyCore Linux and when I tried to install RVM (needed a portable linux distro for QA Automation) I keep getting an error sh: syntax error:unexpected redirection. I am unsure why I am ...
7
votes
4answers
3k views

Make cd automatically ls

I find that I often do the following: %> cd bla/bla %> ls I would like it that whenever I cd into a directory it automatically does an ls. I fiddled with my .bashrc for a while, but couldn't ...
3
votes
1answer
323 views

Removing redirection operator does not change output. Why?

I saw this usage of redirection somewhere, and thought it was a typo: grep root < /etc/passwd But after I run it, I saw that it gives the same output with grep root /etc/passwd: $ grep root ...
4
votes
1answer
88 views

Quoting in a function results in error

How should I write the command variable to get the expected behavior? #!/bin/bash function f ( ) { echo "$2" } command="f --option=\"One Two Three\" --another_option=\"Four Five Six\"" $command ...
7
votes
2answers
773 views

How to hinder root from running a script

The Glassfish application server provides scripts to administer the application server and also start and stop them and I would like to restrict the root user from running this script. The reason is ...
4
votes
1answer
1k views

shorthand for feeding contents of multiple files to the stdin of a script

Hi good people of this community, Say I have a script called script, that reads from stdin and spits out some results to the screen. If I wanted to feed it contents of one file, I would have typed: ...
3
votes
3answers
2k views

How can I test if a program is running from within a script

Let's assume that another user started a bunzip process, and I have a script that I'd like to start running after that bunzip finishes. What's the best way to check from inside my script that the ...
4
votes
3answers
1k views

Indirect return of all elements in an array

The Bash man page describes use of ${!a} to return the contents of the variable whose name is the contents of a (a level of indirection). I'd like to know how to return all elements in an array using ...
8
votes
2answers
1k views

Why does a bash here-string add a trailing newline char?

The following examples show that a newline is added to a here-string. Why is this done? xxd -p <<<'a' # output: 610a xxd -p <<<'a ' # output: 610a0a