shell

Quoting command-line arguments in shell scripts

The following shell script takes a list of arguments, turns Unix paths into WINE/Windows paths and invokes the given executable under WINE. #! /bin/sh if [ "${1+set}" != "set" ] then echo "Usage; winewrap EXEC [ARGS...]" exit 1 fi EXEC="$1" shift ARGS="" for p in "$@"; do if [ -e "$p" ] then p=$(winepath -w $p) fi A...

MySQL shell on Windows

The command line interface to MySQL works perfectly well in itself, but when using my local copy I'm forced to interact with it using the old-fashioned DOS windows. Is there some way I can redirect it through a better shell? ...

How to add submenu items to the Windows Explorer context menu?

I can create a menu item in the Windows Explorer context menu by adding keys in the registry to HKEY_CLASSES_ROOT\Folder\shell. How can I create submenu items to the just created menu item? ...

Path to Program-Files on remote computer

How do I determine the (local-) path for the "Program Files" directory on a remote computer? There does not appear to any version of SHGetFolderPath (or related function) that takes the name of a remote computer as a parameter. I guess I could try to query HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir using remote-regis...

JavaScript interactive shell with completion

For debugging and testing I'm searching for a JavaScript shell with auto completion and if possible object introspection (like ipython). The online JavaScript Shell is really nice, but I'm looking for something local, without the need for an browser. So far I have tested the standalone JavaScript interpreter rhino, spidermonkey and goog...

Why does the Bourne shell printf iterate over a %s argument?

What's going on here? printf.sh: #! /bin/sh NAME="George W. Bush" printf "Hello, %s\n" $NAME Command line session: $ ./printf.sh Hello, George Hello, W. Hello, Bush UPDATE: printf "Hello, %s\n" "$NAME" works. For why I'm not using echo, consider echo.sh: #! /bin/sh FILE="C:\tmp" echo "Filename: $FILE" Command-line: $ ./echo.s...

Worth switching to zsh for casual use?

The default shell in Mac OS X is bash, which I'm generally happy to be using. I just take it for granted. It would be really nice if it auto-completed more stuff, though, and I've heard good things about zsh in this regard. But I don't really have the inclination to spend hours fiddling with settings to improve my command line usage by a...

An easy way to diff log files, ignoring the time stamps?

I need to diff two log files but ignore the time stamp part of each line (the first 12 characters to be exact). Is there a good tool, or a clever awk command, that could help me out? ...

Is it possible to craft a glob that matches files in the current directory and all subdirectoies?

For this directory structure: . |-- README.txt |-- firstlevel.rb `-- lib |-- models | |-- foo | | `-- fourthlevel.rb | `-- thirdlevel.rb `-- secondlevel.rb 3 directories, 5 files The glob would match: firstlevel.rb lib/secondlevel.rb lib/models/thirdlevel.rb lib/models/foo/fourthlevel.rb ...

Boolean Expressions in Shell Scripts

What's the "right" way to do the following as a boolean expression? for i in `ls $1/resources`; do if [ $i != "database.db" ] then if [ $i != "tiles" ] then if [ $i != "map.pdf" ] then if [ $i != "map.png" ] then svn export -q $1/resources/$i ../MyProject/Resources/$i ... ...

How do you parse a filename in bash?

I have a filename in a format like: system-source-yyyymmdd.dat I'd like to be able to parse out the different bits of the filename using the "-" as a delimiter. ...

Get CPU usage in shell script?

I'm running some JMeter tests against a Java process to determine how responsive a web application is under load (500+ users). JMeter will give the response time for each web request, and I've written a script to ping the Tomcat Manager every X seconds which will get me the current size of the JVM heap. I'd like to collect stats on the ...

WScript.Shell and blocking execution?

I'm using WScript to automate some tasks, by using WScript.Shell to call external programs. However, right now it does not wait for the external program to finish, and instead moves on. This causes issues because I have some tasks dependent on others finishing first. I am using code like: ZipCommand = "7za.exe a -r -y " & ZipDest & Bu...

prepend to a file one liner shell?

This is probably a complex solution. I am looking for a simple operator like ">>", but for prepending. I am afraid it does not exist. I'll have to do something like mv $F tmp cat header tmp > $F Anything smarter? (I am not fond of tmp files) ...

How to check if a directory exists in a bash shell script

What command can be used to check if a directory does or does not exist, within a bash shell script? ...

How can I send the stdout of one process to multiple processes using (preferably unnamed) pipes in Unix (or Windows)?

I'd like to redirect the stdout of process proc1 to two processes proc2 and proc3: proc2 -> stdout / proc1 \ proc3 -> stdout I tried proc1 | (proc2 & proc3) but it doesn't seem to work, i.e. echo 123 | (tr 1 a & tr 1 b) writes b23 to stdout instead of a23 b23 ...

How do I use a pipe in the exec parameter for a find command?

I'm trying to construct a find command to process a bunch of files in a directory using two different executables. Unfortunately, -exec on find doesn't allow to use pipe or even \| because the shell interprets that character first. Here is specifically what I'm trying to do (which doesn't work because pipe ends the find command): fi...

Debugger for unix pipe commands

As I build *nix piped commands I find that I want to see the output of one stage to verify correctness before building the next stage but I don't want to re-run each stage. Does anyone know of a program that will help with that? It would keep the output of the last stage automatically to use for any new stages. I usually do this by sendi...

How can I check for a file size and add that result in an Excel spreadsheet in Perl?

Currently I monitoring a particular file with a simple shell one-liner: filesize=$(ls -lah somefile | awk '{print $5}') I'm aware that Perl has some nice modules to deal with Excel files so the idea is to, let's say, run that check daily, perhaps with cron, and write the result on a spreadsheet for further statistical use. ...

Delete all but the 4 newest directories

How would you do this in bash ...