bash

pcmanfm arguements; bash

I am using ubuntu, fluxbox, pcmanfm as filemanager, xmms2 as music player. My goal: add songs to xmms2 playlist easily with pcmanfm. I have this script that works for single files: path= $1 if [ -d "$path" ]; then #if directory xmms2 radd "$path" else if [ -e "$path" ]; then #if not directory, but file xmms2 add "$path" ...

Problem redirecting a C program output in bash

I've coded a program in C that sends messages to the stdout using printf and I'm having trouble redirecting the output to a file (running from bash). I've tried: ./program argument >> program.out ./program argument > program.out ./program >> program.out argument ./program > program.out argument In each case, the file program.out is...

environment path loading incorrectly in bash

I recently installed the Macports port of Ruby19 and it's changed my environment settings to point to opt/local in the first instance rather than usr/local where I have my standard 1.8.7 install. I've tried updating my ~/.profile by adding the usual export PATH etc. as the last line but to no avail. I have to run the .profile file each ...

Sending arp via shell

Hi there! Is there a way a send custom (and event undemanded) arp responses via shell (e.g. by hand or by a shell script) on MacOS X or any other UNIX? In addition, is there a way of making the software ask for the MAC representation for all IPs in the current subnet without sending pings the anyone? Thanks, Max ...

Functions in Makefile

Hello! I am writing a Makefile with a lot of repetitive stuff, e.g. debug_ifort_Linux: if [ $(UNAME) = Linux ]; then \ $(MAKE) FC=ifort FFLAGS=$(difort) PETSC_FFLAGS="..." \ TARGET=$@ LEXT="ifort_$(UNAME)" -e syst; \ else ...

unix shell nightmares

What are the worst/best unix shell nightmares? My favourites are: rm -rf / tmp/foo (deletes everything if you are root; typo :-( ) rm -rf .* (deletes everything if you are root; not just all hidden files) Files in * that are used as parameters, e.g. after touch -- -rf, rm * eventually evaluates to rm -rf foo bar cat foo | sed 's/foo/ba...

How many ways can I get Bash alias completion on a partial substring?

Question: I have a question that is apparently not answered by this already-asked Bash completion question on Stack Overflow. The question is, how to get Bash alias completion (for any alias) on a partial substring. Example: For example, assume I have the following aliases: open.alicehome="cd /usr/home/alice" open.bakerhome="cd /usr/ho...

bash: get list of commands starting with a given string

Is it possible to get, using Bash, a list of commands starting with a certain string? I would like to get what is printed hitting <tab> twice after typing the start of the command and, for example, store it inside a variable. ...

bash: get list of variables whose name matches a certain pattern

In bash echo ${!X*} will print all the names of the variables whose name starts with 'X'. Is it possible to get the same with an arbitrary pattern, e.g. get all the names of the variables whose name contains an 'X' in any position? ...

xargs doesn't recognize bash aliases

I'm trying to run the following command: find . -iname '.#*' -print0 | xargs -0 -L 1 foobar where "foobar" is an alias or function defined in my .bashrc file (in my case, it's a function that takes one parameter). Apparently xargs doesn't recognize these as things it can run. Is there a clever way to remedy this? ...

How to delegate within a crontab to use another file as a crontab? aka Crontab in SVN/CVS?

Maybe theres another solution to this. I built a web app that requires 5-10 crons to keep it maintained and various intervals. I want to check-in the crontab into version control, so that it can be easily deployed to other servers. I would like to be able to put a line in the /etc/crontab file that would tell it to look into /myapp/app....

The following bash command will spawn processes to kernel death. Can you explain the syntax?

I stumbled upon this page and can't understand how this works. This command "exponentially spawns subprocesses until your box locks up". But why? What I grok less are the colons. user@host$ :(){ :|:& };: ...

Bash completion for make with generic targets in a Makefile

Hello, I have a Makefile where most of my targets are created generically through a canned sequence. It seems that bash completion only suggests completions for normal targets, e.g. target_name: #$@ and not for generic targets. Is there any way to make bash completion complete all the targets, even though they are not made ex...

escaping 'run' command line options in cygwin

Hey everyone, I'm having issues passing arguments through "run" to the windows side To demonstrate, it looks something like this: run C:\foo.exe /BUILD The '/BUILD' parameter is never passed to the executable. Anyone know of a way to get around this? Thanks! ...

Ruby - See if a port is open

I need a quick way to find out if a given port is open with Ruby. I currently am fiddling around with this: require 'socket' def is_port_open?(ip, port) begin TCPSocket.new(ip, port) rescue Errno::ECONNREFUSED return false end return true end It works great if the port is open, but the downside of this is that occasio...

How do I determine sound card type with bash?

In bash, how do I determine what sound card is installed? I'm trying to create a plugin for Rhythmbox, and I'd like to test for this in a configuration script. Edit: On my machine, I needed to use sudo to be able to use lspci and lsmod. @Quassnoi's answer using cat worked without extra privileges. ...

cygwin interop questions

A quick couple of Cygwin questions that I am not quite sure how to search in order to find the answer myself: Question: When I run which perl on my cygwin installation, it doesn't point to my pre-installed windows installation, it points to the cygwin one. How can i change it so it points to my windows based perl installation: /cygd...

Bash Scripting - shell command output redirection

Hi all, Can someone help explain the following: If I type: a=`ls -l` Then the output of the ls command is saved in the variable a but if I try: a=`sh ./somefile` The result is outputed to the shell (stdout) rather than the variable a What I expected was the result operation of the shell trying to execute a scrip 'somefile' to b...

Bash/DOS/PowerShell script to list most recent versions of files?

We have a list of (let's say 50) reports that get dumped into various folders depending on certain conditions. All the reports have standard names eg. D099C.LIS, D18A0.LIS etc. Sometimes a report can exist in up to 5 different locations, and I need to generate a list of all the locations of the most recent version of each report. I ca...

Change script directory to user's homedir in a shell script

In my bash script I need to change current dir to user's home directory. if I want to change to user's foo home dir, from the command line I can do: cd ~foo Which works fine, however when I do the same from the script it tells me: ./bar.sh: line 4: cd: ~foo: No such file or directory Seams like it would be such a trivial thing, b...