shell

Does pdksh (public domain korn shell) support associative arrays?

I recently ran up against a wall doing some bash shell programming where an associative array would have solved my problems. I googled about features of the Korn shell and learned that it supports associative arrays, so I installed Cygwin's pdksh (public domain korn shell). However, when trying to create an associative array in the pre...

How do I get bash completion to work with aliases?

Case in point: I'm a on mac with bash v3.2.17, I'm using git installed via macports with the bash_completion variant. When I type git checkout m<tab>. for example, I get it completed to master. However, I've got an alias to git checkout, gco. When I type gco m<tab>, I don't get the branch name autocompleted. Ideally I'd like autocom...

Double Spacing Complex Sed Output

Let me start off by saying that I know there is probably a much simpler way to do this. But this is what i have and yes hopefully I can make some improvements and/or simplifications at the end. Goal as of this moment To double space the output stored in the $tmp variable below and individually number each line. Doing this should give m...

PHP: exec() error responses?

Below is the command I tried executing, without success: exec('ln -s ' . PLUGIN_DIR . '/.htaccess ' . ABSPATH . '/.htaccess'); When you add a die() at the end, it catches that there's an error: exec('ln -s ' . PLUGIN_DIR . '/.htaccess ' . ABSPATH . '/.htaccess') or die('what?!'); For the above exec() statement, a permissions proble...

BASH while read loop breaking early

I've been banging my head against for wall for a while with this one. I want to SSH into a set of machines and check whether they are available (accepting connections and not being used). I have created a small script, tssh, which does just that: #!/bin/bash host=$1 timeout=${2:-1} ssh -qo "ConnectTimeout $timeout" $host "[ \`who | c...

Logging terminal commands in *nix

Is there a way to log(/var/log) commands executed by users in the *nix terminal? ...

How do I get data from stdin using os.system()

The only reliable method that I a have found for using a script to download text from wikipedia is with cURL. So far the only way I have for doing that is to call os.system(). Even though the output appears properly in the python shell I can't seem to the function it to return anything other than the exit code(0). Alternately somebody co...

How to add file extensions based on file type on Linux/Unix?

This is a question regarding Unix shell scripting (any shell), but any other "standard" scripting language solution would also be appreciated: I have a directory full of files where the filenames are hash values like this: fd73d0cf8ee68073dce270cf7e770b97 fec8047a9186fdcc98fdbfc0ea6075ee These files have different original file types...

Capturing nslookup shell output with C#

I have a command-line process I would like to automate and capture in C#. At the command line, I type: nslookup This launches a shell which gives me a > prompt. At the prompt, I then type: ls -a mydomain.local This returns a list of local CNAMEs from my primary DNS server and the physical machines they are attached to. What I wou...

How to write a unix filter that outputs only a line every N lines

Suppose to feed the filter standard input with these line: line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10 It would be nicer if someone tell me how to write a script that prints only every 4 lines, in the case of the example input above: line 1 line 5 line 9 ...

scripted files download under Windows

Hey, I'm about to be forced to write a script to download some number of files under Windows XP. The machines the script will be run at are all behind a proxy, and the proxy settings are entered into the IE configuration. What came to my mind was either to somehow call IE from the command line, and using its configuration download file...

kill background process when shell script exit

I am looking for a way to clean up the mess when my top-level script exit. Especially if I want to use "set -e", I wish the background process would die when the script exit. thanks ...

Is there a standalone alternative to activerecord-like database schema migrations?

Hi! Is there any standalone alternative to activerecord-like migrations. Something like a script that is able to track current schema version and apply outstanding migrations. Basically, these migration files could be just a plain SQL files, something like: [timestamp]_create_users.sql reverse_[timestamp]_create_users.sql Language of...

Windows Explorer directory as bundle

I have been investigating for some time now a way to prevent my user from accidently entering a data directory of my application. My application uses a folder to store a structured project. The folder internal structure is critic and should not be messed up. I would like my user to see this folder as a whole and not be able to open it (...

How can I run the first process from a list of processes stored in a file and immediately delete the first line as if the file was a queue and I called "pop"?

I'd like to call the first command listed in a simple text file with \n as the separator in a pop-like fashion: Figure 1: cmdqueue.lst : proc_C1 proc_C2 proc_C3 . . Figure 2: Pop the first command via popcmd: proc_A | proc_B | popcmd cmdqueue.lst | proc_D Figure 3: cmdqueue.lst : proc_C2 proc_C3 proc_C4 . . ...

How can I negate the return-value of a process?

I'm looking for a simple, but cross-platform negate-process that negates the value a process returns. It should map 0 to some value != 0 and any value != 0 to 0, i.e. the following command should return "yes, nonexistingpath doesn't exist": ls nonexistingpath | negate && echo "yes, nonexistingpath doesn't exist." The ! - operator is ...

Getting Emacs ansi-term and Zsh to play nicely

I've been trying to use Zsh within my emacs session, without emacs remapping all the Zsh keys. I found ansi-term works pretty well for this but, I'm still having some problems. I was getting lots of junk characters outputted with, I was able to fix it with: ## Setup proper term information for emacs ansi-term mode [[ $TERM == eterm-colo...

Shell scripting: die on any error

Suppose a shell script (/bin/sh or /bin/bash) contained several commands. How can I cleanly make the script terminate if any of the commands has a failing exit status? Obviously, one can use if blocks and/or callbacks, but is there a cleaner, more concise way? Using && is not really an option either, because the commands can be long, ...

What is the best way to write a wrapper function that runs commands and logs their exit code

I currently use this function to wrap executing commands and logging their execution, and return code, and exiting in case of a non-zero return code. However this is problematic as apparently, it does double interpolation, making commands with single or double quotes in them break the script. Can you recommend a better way? Here's the...

Linux how do I put double quotes around a file before piping it to tar?

I use ls to obtain my filename which has white space so it looks something like: my file with whitespace.tar.bz2 I want to pipe this to tar similar to: ls | grep mysearchstring | tar xvjf How can I insert double quotes before piping it to tar? ...