shell

Shell script help! Looping over directories under a directory

I want to write a shell script that loops through all directories under a directory, and call a java program with the directory name as an argument at each iteration. So my parent directory is provided as an argument to the shell script: eg: . myShell.sh /myFolder/myDirectory There are 100 directories under /myFolder/myDirectory. F...

Shell scripting debug help - Iterating through files in a directory.

#!/bin/bash -f files = 'ls /myDir/myDir2/myDir3/' for file in $files do echo $file java myProg $file /another/directory/ done What i'm trying to do is iterate through every file name under /myDir/myDir2/myDir3/, then use that file name as the first argument in calling a java program (second argument is "/another/directory...

GUI Using Shell Batch File

I'm now going to develop a program that will generate Shell Batch Files(*.sh), but I want to know some things: It's possible to show GUIs using they? How to do this? ...

How can I use arrays in unix shell?

Hi, I use code in !/bin/sh like this: LIST1="mazda toyota honda" LIST2="2009 2006 2010" for m in $LIST1 do echo $m done As you can see this currently prints out only the make of the car. How can I include the year to each "echo" based on the same positions so that I get results like: mazda 2009 toyota 2006 honda 2010 ? ...

is_number function doesn't work for me - unix shell

When I pass in 2009 as a arg to this shell function it returns 0, why? isyear() { case $arg in [0-9][0-9][0-9][0-9]) NUM=1 ;; *) NUM=0 ;; esac echo $arg } ...

How do I process something like this in unix shell?

Hi All, What would be the best approach to process a call like this to my shell script? ./cars Mazda Toyota 2010 Honda BMW VW 2009 So that it prints out: Mazda 2010 Toyota 2010 Honda 2009 BMW 2009 VW 2009 I can't use arrays because it's the most simple version of shell so it doesn't support them. Any ideas? ...

Case statement in shell - problem

Hi, I'm completely new to shell and I'm trying to include a case where the function's arg #1 is greater or equal 12 then it should return 1. But the below doesn't work. case $1 in -ge 12) NUM=1 ;; *) NUM=0 ;; esac echo $NUM ...

Portable way to get file size (in bytes) in shell?

On Linux, I use stat --format="%s" FILE, but Solaris I have access to doesn't have stat command. What should I use then? I'm writing Bash scripts, and can't really install any new software on the system. I've considered already using: perl -e '@x=stat(shift);print $x[7]' FILE or even: ls -nl FILE | awk '{print $5}' But neither of...

How often are windows handles reused

I note an applications handle when I use the shell function to open it. I then use that handle to close the application later. However the user can also close that other application himself. Can that handle then be reused by windows so that when I use that handle I close a different process. If it is possible is it likely? ...

Problem with including an "image" in shell program.

Hi All, I'm writing a program where at some point in my loop I want to print to output whatever is stored in a separate file (an image). But if I code it like this: for c in $LIST do clear ./image.0 done And the "image.0" file contains only an image like this: +----+ | | | | | | | ======== Then when I run my program I ...

How to set read command to execute without having to press Enter button in shell?

Hi All, I use the below code to assign a given by the user character to variable G: read G However in order to move forward with executing of my script I need to press enter button. Is it possible to set the read command somehow that it show process forward to the next line immediately after it receive the one letter from stdin? ...

Get result from shell script objective-c

I would like to run a shell script, from a file or from an objective-c string (within the code). I would also like the shell script's result to be stored to a variable. I would not like the shell script to be split into arguments (such as setLaunchPath when I run it). For example: running this shell script "mount_webdav idisk.mac.com/...

Exit entire program from a function call in shell?

Hi, I have a function which I use in my shell script and based on a certain condition I'd like to call "exit 0" in that function so that the entire script exits. But for some reason the program still runs after calling exit 0 in the function. Why? check() { printf "Would you like to try again?\n" read S if [ "$S" = "y" ] then ...

How to detect a filename within a case statement - in unix shell?

Hi I coded the below code and if no -l or -L option is passes to the script I need to assume (detect) whether a filename was passed as a param. The below third condition only matches if filename is one lowercase character. How can I make it flexible to match upper and lower case letters or variable length of the string? while [ $# -gt...

How to detect the current directory in which I run my shell script?

How may I detect the name of the directory (or better yet the entire path) in which my shell script is run? ...

What is the use of TNS_ADMIN variable in Oracle?

Hi All, Please tell me what is the use of TNS_ADMIN parameter in Oracle? I am working on Unix using oracle database. Is this parameter is required to locate the sqlplus. I am executing a script in which a update query is executed on Oracle Database. The script fails with 127 error code when executed with crontab. The script content...

how to grep a variable in the shell program?

#!/bin/bash for ((var=0; var<20; var++)) do echo " Number is: $(grep 'Multiple_Frame = echo **$var**' 20mrf.txt | wc -l)" >>statisic.txt done This shell program cannot produce correct result which maybe the reason of wrong variable returning in the second grep command. How can I grep a variable within the second echo sentence? to...

Why doesn't division produce a result in shell programming?

I have a shell programe, a little part of it can be seen as following: count=1000 total=100000 percent=`expr $count/$total` it cannot produce the division result, in the result file, only 1000/100000 was shown. Any help? Many thanks.~ ...

Display socket options

How I can see from shell what socket options are set? In particular I'm interesting to know if SO_BROADCAST is set? ...

Escape backquote in a double-quoted string in shell

For the command: /usr/bin/sh -c "ls 1`" (a backquote after 1). How to make it run successfully? Adding a backslash before "`" does not work. ` is a special char as we know, and I tried surrounding it with single quote too (/usr/bin/sh -c "ls 1'`'"), but that doesn't work either. The error always are: % /usr/bin/sh -c "ls 1\`" Unmatc...