shell

A script to ssh into a remote folder and check all files?

I have a public/private key pair set up so I can ssh to a remote server without having to log in. I'm trying to write a shell script that will list all the folders in a particular directory on the remote server. My question is: how do I specify the remote location? Here's what I've got: #!/bin/bash for file in [email protected]:dir/*...

How to address an issue while sourcing an env file in bash ?

Some issue arise when sourcing one of your env file (a series of variable exporting) for instance: ... export MY_ROOT=/Soft/dev/blah/blah export MY_BIN=${MY_ROOT}/bin ... results in $. my_env.sh $echo $MY_BIN /bint/dev/blah/blah => "/bin" seems to overwrite the begining of the variable instead of suffixing it.. Any idea? By the...

How to get the window handle of the desktop

The Windows API provides an API GetDesktopWindow( ) which returns the window handle But I tested with Spy++ and I find that the window handle of the desktop and the window handle of the "Windows Desktop" is not the same. As the "Windows Desktop" is a list view, do I need to do the following 1) HANDLE hWnd = GetDesktopWindow() ; 2) ...

Security or other gotcahs in Apache-CGI-Bash application?

I've taken over supporting a time- and expense-entry system. Apache's CGI. CGI programs are written in bash :) I'm going to add some features into it and exposing it out to many more users, but prior to that wanted to get some thoughts on what else needs to be looked-at first in terms of security, holes, CGI gotchas, &c. Not a lot of...

In UNIX shell scripting: What is $! ?

What is the meaning for $! in shell or shell scripting? I am trying to understand a script which has the something like the following. local@usr> a=1 local@usr> echo $a 1 local@usr> echo $!a a It is printing the variable back. Is it all for that? What are the other $x options we have? Few I know are $$, $*, $?. If anyone can point me ...

linux like behavior in windows shell - running ruby without "ruby" appended to the command?

This is probably a really silly question bu tI can't seem to find an answer since I'm apparently failing on keywords. You know how you can run commands from the commandline in linux if you put a line on the top of your .rb file so you don't have to type ruby myfile.rb all the time and can just do ./myfile.rb ? Is it possible to have the...

Shell script to grab selected text and alter it?

How can I make a shell script that will know where the caret is and grab selected text, so I can wrap the text in something? For example, this is a script from a Textmate bundle: <${1:p}>$TM_SELECTED_TEXT</${1/\s.*//}> It grabs the text and wraps it in open/close HTML tags. And it is variable so the second tag is mirrored as you type...

Cygwin Shell Scripts

I'm not running cygwin, but I have the cygwin ash.exe in my %PATH% as sh.exe and have cygwin1.dll in %PATH% I am trying to invoke some shell scripts (named with no extension) using sh -c shell-script-name but I get a "permission denied" error. If I run sh and run ./script I also get this error. I have a proper #!/bin/sh shebang line ...

How to check the ls version

This topic is about the util 'ls' The BSD version uses the parameter '-G' to color up the output, while the Linux version uses parameter '--color' Also the environment variable to set the colors is different: BSD: $LSCOLORS Linux: $LS_COLORS But now the problem is: I want to determine which version is installed (using a small Shell scr...

How to format the date in korn shell script to DD-MON-YYYY?

How do I format a date in a korn shell script to DD-MON-YYYY? I have tried the following: date '+%d-%h-%Y' It returns 04-Nov-2009 I need for the Nov to be NOV (all caps). Can this be done with the date utility? ...

escape character in vim command

I want to run command like this: vim -c "%g/blablabla/norm /str<ESC>cwSTR" file How I write escape character in the command? ...

Convert a Cygwin PID to a Windows PID

I have a process I spawn with a Cygwin shell script, and I am unable to kill it with the kill command. Even with the Cygwin kill with the -f option, I get this message: kill: couldn't open pid 1234 I would like to try to kill it with PsKill, but I cannot find a way to convert the Cygwin PID to a Windows PID that PsKill will understand...

What is scala -i command-line option supposed to do ?

I'm finding the scala '-i' command line option quite useful for running some scala code and then dumping me into an interactive shell so I can prod/inspect the things it defined. One thing which completely mystifies me though: why does it load and run the script twice ? For example, given file test.scala containing the cannonical prin...

Multi-threaded BASH programming - generalized method?

Ok, I was running POV-Ray on all the demos, but POV's still single-threaded and wouldn't utilize more than one core. So, I started thinking about a solution in BASH. I wrote a general function that takes a list of commands and runs them in the designated number of sub-shells. This actually works but I don't like the way it handles acc...

Run python script without DOS shell appearing

Is there any way to run a python script in Windows XP without a command shell momentarily appearing? I often need to automate word perfect (for work) with python, and even if my script has no output, if I execute it from without WP an empty shell still pops up for a second before disappearing. Is ther any way to prevent this? Some kind o...

Generic Command Line SQL Program?

Is there any application/project that provides you with a command line SQL client that will work with multiple databases and/or provides a mechanism for writing your own drivers? Put another way, I'm looking for something like the mysql command line client or SQL*Plus for Oracle, but that's database agnostic. All platforms welcome,...

How do I launch an editor from a shell script?

I would like my tcsh script to launch an editor (e.g., vi, emacs): #!/bin/tcsh vi my_file This starts up vi with my_file but first displays a warning "Vim: Warning: Output is not to a terminal" and my keystrokes don't appear on the screen. After I kill vi, my terminal window is messed up (no newlines), requiring a "reset". I tried "...

How to egrep variable-Unix shell script

I’m trying to validate input by using egrep and regex.Here is the line from script (c-shell): echo $1 | egrep '^[0-9]+$' if ($status == 0) then set numvar = $1 else echo "Invalid input" exit 1 endif If I pipe echo to egrep it works, but it also prints the variable on the screen, and this is something I don't need. ...

How to set mutiple words variable from command line input in C shell

I'm writing a script to search for a pattern in file. For example scriptname pattern file1 file2 filenN I use for loop to loop through arguments argv, and it does the job if all arguments are supplied. However if only one argument is supplied (in that case pattern ) it should ask to input file name or names, and then check for pattern....

How do I get vim's :sh command to source my bashrc?

Whenever I start a shell in vim using :sh, it doesn't source my ~/.bashrc file. How can I get it to do this automatically? ...