a possible solution could be:
This script needs to be called with one argument. That must be a directory name. The script will then change to that directory and do a simple ls -l.
1st check if there is one argument submited (if not quit)
2nd remember the current working directory
3rd check if current woring directory and the target directory (submited in $1) is identical.
- If thats the case, just do an ls -l and then quit.
- If this is not the case, change to the target directory. Check if cd was successfull and then run this script ($0) again with now the current directory as the argument.
The script itself resides still in the old directory (or somewhere else). Therefore a script call with a relative path would fail. So the old path before changing to the target directory must be submited as well to locate the script. If the script was called with an absolute path, $0 can be used without changes (will be located anyway).
You can ommit this problem if you put your script into your $PATH.
Some modification for the given script to handle spaces in paths, etc.:
#!/bin/ksh
[[ -z "${1}" ]] && { print "Please specify a path";return 1; }
[[ -d "${1}" ]] && { print "Specified path is a directory! You should specify a path to executable.";return 1; }
[[ -x "${1}" ]] || { print "Specified path is not executable!";return 1; }
typeset OldPwd=$(pwd)
typeset NewPwd="${1%/*}"
typeset ExecName="${1##/}"
typeset -i RC=0
# The file could be located in current directory, ex. `script.ksh script.ksh`
[[ -n "${NewPwd}" ]] && cd "${NewPwd}"
"${ExecName}"
RC=$?
print -- "Exited with status ${RC}"
# Usually `cd -` would work as well
cd "${OldPwd}"
return ${RC}
Note, that is probably not so important for you:
You should expect some problems with "current directory" if the file is a link. To obtain real directory that contain the executable, and not the link, you should do some more things. But this is probably not what you would like to do.
Hi guys,
I've create 3 shells concerning my work, which named as 1.sh, 2.sh and 3.sh.
However, how can I make an interactive query for these shells just like the old (fdisk) in windows9x. I want to make an interface tells the user just like this:
Press 1 to execute "1.sh"
Press 2 to... (5 Replies)
Hi,
I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database.
For instance:
USER CITY
--------- ----------
A CITY_A
B CITY_B
C ... (2 Replies)
Hi All,
O/S: Linux 86x64 Red Hat
I have a sql script that queries top consuming processes of Linux using TOP commnd.
Now I need to automate this task and pass the top processes i.e., PID to the sql script through unix shell script.
Could anyone please let me know how to achieve this.
... (2 Replies)
Hi
i want write a script for list of sysbase are having access or open.
then i wrote like:
USER="abc"
PASS="xyz"
SERVER="SCCS"
DB="blue"
WORK_DIR="/usr/home/ramakrishna"
set -x
isql -U${USER} -P${PASS} -S${SERVER}<<EOF>$WORK_DIR/output.log
go
use blue (database name)
go
use... (0 Replies)
Hi,
I have a requirement as below which needs to be done viz UNIX shell script
(1) I have to connect to an Oracle database
(2) Exexute "SELECT field_status from table 1" query on one of the tables.
(3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
I want to perform few post-session success tasks like update a status to 'true' in one of the sql database table, update date values to current system date in one of the configuration table in sql. How do i achieve this in a post session command?syntax with example will be helpful. (3 Replies)
Hi,
I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram
I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Dear all
I want to execute some isql command from unix shell script. Kindly suggest me. isql command mention below.
isql -U -P
use gdb_1
go
select count (*) from table_x
go (3 Replies)
Hi
I want to get the a field from a SQL query into unix shell script variable. the whole situation is like this.
1. Opened a cursor to a table in DB2 databse.
2. Fetching individual rows with the help of cursor.
3. Each row has 4 fields.
I want each of the field in individual shell... (1 Reply)
I don't know anything about UNIX. I have been developing on NT platform and now a batch file I was running in my java code must work on UNIX instead. How do I change the below .bat file into a shell script that can be run on UNIX? Thanks in advance for your help.
@ECHO OFF
D:... (1 Reply)