shell

unix path searching C function

Hi, I am programming a UNIX shell and I have to use the execv() system call to create a process. One of the parameters for execv() is the filepath for the executable. So if somebody types in /bin/ls, it will run the ls executable. But what I need is a function that when ls is typed, it will search for the filepath of ls (like the "whi...

${1:+"$@"} in /bin/sh

I've noticed that sometimes wrapper scripts will use ${1:+"$@"} for the parameters rather than just "$@". For example, http://svn.macosforge.org/repository/macports/trunk/dports/editors/vim-app/files/gvim.sh uses exec "$binary" $opts ${1:+"$@"} Can anyone break ${1:+"$@"} down into English and explain why it would be an advantage ove...

Customized command line parsing in Python

I'm writing a shell for a project of mine, which by design parses commands that looks like this: COMMAND_NAME ARG1="Long Value" ARG2=123 [email protected] My problem is that Python's command line parsing libraries (getopt and optparse) forces me to use '-' or '--' in front of the arguments. This behavior doesn't match my requirements. An...

Bash autocompletion in Emacs shell-mode

In the GNOME Terminal, Bash does smart auto-completion. For example apt-get in<TAB> becomes apt-get install In Emacs shell-mode, this auto-completion doesn't work, even after I explicitly source /etc/bash_completion. The above example sticks as in or auto-completes with a filename in the current directory rather than a valid apt-ge...

Setting PDQ inside an SPL - local scope?

In order to fine tune allocation of PDQ resources depending on the time of day that batch jobs run, we have a utility that sets PDQPRIORITY based on some day of week / hour of day rules, eg: PDQPRIORITY=$(throttle); export PDQPRIORITY However, this is fixed at the time the script starts, so long running jobs never get throttled up or ...

How do I use Ruby for shell scripting?

I have some simple shell scripting tasks that I want to do for example: Selecting a file in the working directory from a list of the files matching some regular expression I know that I can do this sort of thing using standard bash and grep but I would be nice to be able to hack quick scripts that will work in windows and linux wi...

Unix shell events?

Is there any way so that i can echo password when asked for in unix shell without use of external binaries ? Something like simple function triggered when password prompt is displayed ...

How do I enter a pound sterling character (£) into the Python interactive shell on Mac OS X?

Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here: Python/editline on OS X: £ sign seems to be bound to ed-prev-word On Mac OS X I can’t enter a pound sterling sign (£) into the Python interactive shell. Mac OS X 10.5.5 Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) European keyboar...

How do I iterate over a range of numbers in bash?

How do I iterate over a range of numbers in bash when the range is given by a variable? I know I can do this: for i in {1..5}; do echo $i; done Which gives: 1 2 3 4 5 Yet how can I replace either of the range endpoints with a variable? This doesn't work: END=5 for i in {1..$END}; do echo $i; done Which prints: ...

UNIX shell written in a reasonable language?

Has anyone ever heard of a UNIX shell written in a reasonable language, like Python? ...

Why do shell script comparisons often use x$VAR = xyes?

I see this often in the build scripts of projects that use autotools (autoconf, automake). When somebody wants to check the value of a shell variable, they frequently use this idiom: if test "x$SHELL_VAR" = "xyes"; then ... What is the advantage to this over simply checking the value like this: if test $SHELL_VAR = "yes"; then ... ...

Setting up pipelines reading from named pipes without blocking in bash

I'm looking to call a subprocess with a file descriptor opened to a given pipe such that the open() call does not hang waiting for the other side of the pipe to receive a connection. To demonstrate: $ mkfifo /tmp/foobar.pipe $ some_program --command-fd=5 5</tmp/foobar.pipe In this case, some_program is not run until some process has ...

How do shell text editors work?

I'm fairly new at programming, but I've wondered how shell text editors such as vim, emacs, nano, etc are able to control the command-line window. I'm primarily a Windows programmer, so maybe it's different on *nix. As far as I know, it's only possible to print text to a console, and ask for input. How do text editors create a navigab...

ExitCodes bigger than 255, possible?

If yes, on which operating system, shell or whatever? Consider the following java program (I'm using java just as an example, any language would be good for this question, which is more about operation systems): public class ExitCode { public static void main(String args[]) { System.exit(Integer.parseInt(args[0])); } } ...

How do I compare strings in Bourne Shell?

I need to compare strings in shell: var1="mtu eth0" if [ "$var1" == "mtu *" ] then # do something fi But obviously the "*" doesn't work in Shell. Is there a way to do it? ...

"Unix shell"-alike script under Windows

Hello everybody. I need some help from the shell-script gurus out there. I have a .txt file (log) that traces the IP addresses of clients on several lines, in a format similar to this one: Line1 - Client IP [192.168.0.1] Other data Line2 - Client IP [192.168.0.2] Other data Line3 - Client IP [192.168.0.3] Other data Line4 - Client IP [...

How do you handle the "Too many files" problem when working in Bash?

I many times have to work with directories containing hundreds of thousands of files, doing text matching, replacing and so on. If I go the standard route of, say grep foo * I get the too many files error message, so I end up doing for i in *; do grep foo $i; done or find ../path/ | xargs -I{} grep foo "{}" But these are less th...

Third-party windows command-line program?

Looking for a better Windows XP command-line interface. The Visual Studio Command Prompt isn't near as nice as the Linux/OSX terminals. Thoughts? edit: Answers: Console on Sourceforge, and the Windows Powershell. Thanks, I'll go dig them up and evaluate them. The Cygwin package is too much overhead for what I want. edit2: Looks like...

Capitalize every file in a directory, in bash, using 'svn mv'.

I need to change the capitalization of a set of files in a subversion working copy, like so: svn mv test.txt Test.txt svn mv test2.txt Test2.txt svn mv testn.txt Testn.txt ... svn commit -m "caps" How can I automate this process? Standard linux install tools available. ...

What Linux shell should I use?

I've used bash, csh, and tcsh. But I asked this question, and Jonathan informed me that csh isn't to be trusted. So what Linux shell is good for development. and why? ...