bash

C# command-line arguments and ls

I'm using MSYS to get some semblance of a sane scriptable shell on Windows :). Now I'm writing a console application, written in C#, that accepts a number of arguments and presents those as options to the user in a dialog box. The actual options correspond to file names, that I'm retrieving with ls. However, trouble appears when I have...

Environment variable within variable

I have an environment variable called $TEST which refers to a directory in my bash script I have a variable called $VARTEST which is = $TEST/dir/file now I want to grep the file specified by $VARTEST so I try to do grep somestring $VARTEST but it doesn't translate $TEST into it's directory I've tried different combinations of {}, "" an...

Simple iptables chain question

Hi, I'm writing a bash script to add simple firewalling for Xen. Here's the actual firewall configuration : Chain INPUT (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- anywhere anywhere Chain FORWARD (policy ACCEPT) target prot opt source destination RH...

I want to make a conditional cronjob

I have a cron job that runs every hour. It accesses an xml feed. If the xml feed is unvailable (which seems to happen once a day or so) it creates a "failure" file. This "failure" file has some metadata in it and is erased at the next hour when the script runs again and the XML feed works again. What I want is to make a 2nd cron job ...

How to show relationships between Todo-lists?

How can I show relations between ToDo-lists? I am using Devtodo. I will give an example. I have my MIT humor in one XML-file: <todo version="0.1.19"> <note priority="low" time="1237320287"> see the MIT humor-video </note> </todo> Other file is about Usenet-humor <todo version="0.1.19"> <note priority=...

Find file in directory from command line

Noob question here, trying to wean myself off of IDEs. In editors/ides such as eclipse and textmate, there are shortcuts to quickly find a particular file in a project directory. Is there a similar tool to do full path completion on filenames within a directory (recursively), in bash or other shell? I have projects with alot of direc...

Bash: Recursively adding subdirectories to the path

... How do you do it? My code/ directory at work is organized in folders and subfolders and subsubfolders, all of which (at least in theory) contain scripts or programs I want to run on a regular basis. Its turning my otherwise picturesque .bashrc into an eyesore! Thanks! ...

Fastest way(s) to move the cursor on a terminal command line?

What is the best way to move around on a given very long command line in the terminal? Say I used the arrow key or Ctrl-R to get this long command line: ./cmd --option1 --option2 --option3 --option4 --option5 --option6 --option7 --option8 --option9 --option10 --option11 --option12 --option13 --option14 --option15 --option16 --option17 ...

bash: how do I write non ascii chars using echo?

Is there an escape sequence, such as \012 or something like that? I want to append on ascii chars to a file using echo ?? >> file ...

CMake : how to use bash command in CMakeLists.txt

I'm wondering how I can use bash command in CMakeLists.txt. What I want is to get the number of processor retrieved using : export variable=`getconf _NPROCESSORS_ONLN` and set NB_PROCESSOR to variable using something like : SET (NB_PROCESSOR variable) So my question is how can I use the getconf command in CMakeLists.txt and how ca...

export problem

Hi. I run the following script in bash 3.2.48: #!/bin/bash export var1='var1' echo "UID=$UID" if [ x"$UID" != x"0" ] then export var2='var2' while ! { sudo -v; }; do { sudo -v; }; done; sudo $0 exit fi echo $var1 echo $var2 exit 0 What I get as output is: UID=1000 UID=0 var1 My question: Why is var2 not exported...

Bash: select a previous command that matches a pattern

I know about the bash history navigation with the Up and Down arrows. I would like a lazy way to select a previous command that matches some regex (that is shorter than the whole command, so it takes less time to be typed). Is it possible with bash? If not, do other shells have such a feature? ...

Scripting for bash screen

I have processes that I background with screen. I'm trying to write a script that attaches to a terminal, executes a couple commands, then detaches. The problem is that when I attach to a terminal, screen directs control to the user. How do I work around this? ...

Is [[ ]] preferable over [ ] in bash scripts?

A co-worker claimed recently in a code review that the [[ ]] construct is to be preferred over [ ] in constructs like if [ "`id -nu`" = "$someuser" ] ; then echo "I love you madly, $someuser" fi He couldn't provide a rationale. Is there one? ...

Getting a 'source: not found' error when using source in a bash script

I'm trying to write (what I thought would be) a simple bash script that will: run virtualenv to create a new environment at $1 activate the virtual environment do some more stuff (install django, add django-admin.py to the virtualenv's path, etc.) Step 1 works quite well, but I can't seem to activate the virtualenv. For those not fam...

BASH - Why does TEST=' .* ' assign the listing of the current directory to TEST?

This is driving me nuts. Everything in single quotes is supposed to be assigned as is, yet if I do the following: TEST=' .* ' echo $TEST I get a bunch of garbage on the screen listing all "dot" files in the current directory... Any help would be appreciated. ...

Move all files except one

How can I move all files except one? I am looking for something like: 'mv ~/Linux/Old/!Tux.png ~/Linux/New/' where I move old stuff to new stuff -folder except a Tux.png. !-sign represents a negation. Is there some tool for the job? ...

How to manage Long Paths in Bash?

I have a problem to manage long paths. How can I get quickly to paths like /Users/User/.../.../.../.../.../Dev/C/card.c I tried an alias alias cd C='cd /Users/User/.../.../.../.../.../Dev/C' but I am unable to do aliases for two separate words. I have long lists of Bash aliases and paths in CDPATH, so I am hesitating to make them ...

Redirecting bash stdout/stderr to two places?

Hey Everyone, This one's been bugging me for a while now. Is it possible to redirect stdout and stderr to both the terminal output and to a program? I understand it's possible to redirect the outputs to a file and to stdout with tee, but I want it to go to a program (my editor [TextMate]) as well as to the terminal output… surely this ...

Variables that work everywhere

How can I set variables that work everywhere? My .bashrc has: Questions='/Users/User/Stackoverflow/Questions' Address='My address' My file has: $Questions $Addres The command "$ cat my_file" in Shell prints "$Questions" and "$Address", instead of "/Users/User/Stackoverflow/Questions" and "My address". Other places where I would li...