shell

Do commands run from current direcotry in a shell script?

In a bash shell script. I tried these two versions: java -jar abc.jar& and CMD="java -jar abc.jar&" $CMD The first verison works, and the second version complains that abc.jar cannot be found. Why? ...

HOWTO: Detect bash from shell script

The scenario is that users are asked to source a script file: $ source envsetup.sh This script file may use bash only feature so we have detect the running shell is bash or not. For other shells that share common syntax with bash, for example, sh, zsh, ksh, I'd like to report a warning. What is the most reliable way to detect the cu...

How can I pass a list of comma separated directories to mkdir from a Makefile?

From the command line you can make multiple directories like so: mkdir -p build/linux/{src,test,debug} How can the same thing be achieved from a Makefile? I've come up with this: # The architecture/OS to compile for ARCH := linux # Object files go here, under the architecture/OS directory BUILD_DIR := build/$(ARCH) # Lis...

How do I convert a bash shell script to a .bat file?

Hi, I have a bash shell script on my Mac, that I need to convert to a .bat file (at least, that's what I've been told) for users that are on PCs. I was wondering the best way to go about this, or if anyone knows of any good references. I don't seem to be asking Google the right question to point me in the right direction. Specificall...

Prompt user to select a directory with a bash script and read result.

Hi, I want to be read a dir with a bash script (actually I am using zsh). I want to list the current folders in the same dir and display it to the user asking them to enter a number to select the correct folder. Please select a Folder eg, 1,2,3. 1. Folder Name 1 (this should the acutal name of the folder in the dir 2. Folder 2 3. Fold...

Set a name for screens with the 'screen' command

Hi, I'm using the 'screen' multiplexer tool on the command shell and open a lot of screens. So I forget wich process ID is wich task. I Would like to set a name for a screen but can't find an option in the manpage. So it looks like this: There are screens on: 5422.pts-1.aws1 (Detached) 5448.pts-1.aws1 (Detached) 5027.pts...

Starting and stopping a process daily using the shell?

I know I can start the process with cron, but how would I go about stopping it? I thought about starting a new process1 everyday at 00:00, then at 23:59 I'd start a process2 doing ps -aux | grep process1, getting the pid from the line and then killing it, but I was wondering if there's be a better way to do it. I could use Python or Jav...

Structured output between linux commands

I am looking for any papers, implementations, or just general ideas about common linux/unix utilities writing/reading structured output/input. The structured output could be anything, xml, jsopn, yaml, etc. This question: http://stackoverflow.com/questions/703163/formatting-shell-output-into-structured-data asks pretty much what I am...

How can I standardize shell script header #! on different hosts?

I manage a large number of shell (ksh) scripts on server A. Each script begins with the line... #!/usr/bin/ksh When I deploy to machine B, C, and D I frequently need to use a different shell such as /bin/ksh, /usr/local/bin/ksh or even /usr/dt/bin/ksh. Assume I am unable to install a new version of ksh and I am unable to create links ...

How to use unix scripts to show all 'n' characters long group of strings?

This IS kind of linked to another question - http://stackoverflow.com/questions/3171552/code-golf-color-highlighting-of-repeated-text I'm tying to figure out a way of breaking a file into all 'n' characters long groups. Eg: If a file comprises of ONLY the following text: ABCDEFGHIJ And we want it broken into sets of 3, the output sh...

ssh to different machine to find the number of file.

echo "`${BOLD}` ***** Checking CoreFile Creation *****`${UNBOLD}`" echo "========================================================" IFS='|' cat configMachineDetails.txt | grep -v "^#" | while read MachineType UserName MachineName do export CHK_COREFILE=`ssh -f -T ${UserName}@${MachineName} ls ~/corefiles ...

Howto show ping output dynamically in a web page?

As part of a diagnostics page I would like to have the user be able to run a "ping", ie an ordinary shell command to send ICMP_ECHO_REQUSTs to a certain IP and display the resuls dynamically in a div in the browser. The backend is Ruby/Rails. I'm past running the command on the server side and reading the output from the ping command. ...

shell script create string of repeated characters

This seems like a simple problem but I couldnt find a ready solution. I need to generate a string of characters "."s as a variable. ie, IN my bash script, I need to generate a string of length 15 ............... I need to do so variably. I tried using this as a base (from: http://www.unix.com/shell-programming-scripting/46584-repeat-ch...

How to assign the parameter list "$@" to another variable?

In a shell script I want a variable p to be equal to "$@", so that the following two lines of code produce the same result: for x in "$p"; do echo $x; done for x in "$@"; do echo $x; done If I do p=$@ or p="$@" this doesn't work. When the command line arguments have spaces in their names, I can't find a simple workaround to this prob...

NFS home / .profile / 3 flavors of UNIX : best practices?

Three flavors of UNIX: Linux, Solaris, IRIX... one NFS mounted home directory. I'd like to have a (slightly) different .profile behavior based on the OS that I'm connecting to. I can hack something together, but I'd like to not re-invent the wheel if it's not necessary. Is there a best practice for splitting out .profiles sections base...

how to group records into bucket based on the timestamp?

i have a list of entries from the logs: 15:38:52.363 1031 15:41:06.347 1259 15:41:06.597 1171 15:48:44.115 1588 15:48:44.125 1366 15:48:44.125 1132 15:53:14.525 1348 15:53:15.121 1553 15:53:15.181 1286 15:53:15.187 1293 the first one is the timestamp, the second one is the value. now i'm trying to group them up by an interval of, sa...

[c/c++] set variable to cmd.exe

Greeting earthmen, Here is my question: How can I create a program which sets variable to current session of cmd.exe e.g. c:\> set myvar Environment variable myvar not defined c:\>myexe.exe c:>set myvar myvar=myvalue The only similar topic that I've found is this - http://stackoverflow.com/questions/774047/how-can-i-change-windows...

vim - write buffer content to stdout

Is there any chance to write the content of the current vim buffer to stdout? I'd like to use vim to edit content that was passed via stdin - without the need of a temporary file to retrieve the modified content. (on Linux/Unix) Added: Is it possible that a plugin/script - that act on quit or save put the buffer content to stdout? ...

Making a command loop in shell with a script

How can one loop a command/program in a Unix shell without writing the loop into a script or other application. For example, I wrote a script that outputs a light sensor value but I'm still testing it right now so I want it run it in a loop by running the executable repeatedly. Maybe I'd also like to just run "ls" or "df" in a loop. I...

Sorting on the last field of a line

What is the simplest way to sort a list of lines, sorting on the last field of each line? Each line may have a variable number of fields. Something like sort -k -1 is what I want, but sort(1) does not take negative numbers to select fields from the end instead of the start. I'd also like to be able to choose the field delimiter too....