12-06-2001
new bourne shell script
Hi mate,
I have modified my script , after your suggestion.
I guess the specific issue for me is the 'parameterization' of the shell script arguments thru a local variable 'index' .is there an alternative to this.
for example : how do i get the argument value of the 'n'th argument to the shell script .
can you address this problem .
Thanks
srinivas
set -x
tot_params=$#
echo "The number of parameters supplied = $tot_params"
dir_params=`expr $# - 1`
echo "The number of dir file names supplied = $dir_params"
#index initialization
index=1
# at least two parameters to be supplied
if test $# -lt 2
then
echo "Please enter at least one directory name parameter and one sort parameter"
exit 1
else
# loop thru the all the directories
# listing the file names
# in ascending or descending order
while test $index -le $tot_params
do
file_name = $($index)
# sort parameter is 'ascending'
if test $# = asc
then
if test -d $file_name
then
echo "listing the files in ascending order....."
ls -l $file_name
index=`expr $index+1`
else
echo "$file_name is not a directory"
exit 1
fi
# sort parameter is 'descending'
elif test $# = dsc
then
echo "File Listing in Descending Order"
if test -d $file_name
then
echo "listing the files in descending order..."
ls -lr $file_name
index=`expr $index+1`
else
echo "$file_name is not a directory"
exit 1
fi
# incorrect sort parameter supplied
else
echo "The Sort argument is $($#)"
echo "The Directory File name is $($index)"
echo "The supplied sort parameter is incorrect"
exit 1
fi
done
fi
if test $? -ne 0
then
echo "sorry..something gone amiss!!!"
else
echo "success"
fi
Last edited by psrinivas; 12-11-2001 at 08:53 AM..
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
i have this assignment.. and i mad this script but there is something wrong with it.. if anyone can tell me.. watz going on... i would appreciate it.. tHnX in advance..
count=1
val=$2
op=$1
ans=0
if
then
if
then
while
do
... (7 Replies)
Discussion started by: dezithug
7 Replies
2. UNIX for Dummies Questions & Answers
Hello,
I'm throwing this out there as a novice to the Unix world...I've
been working on a project that requires me to ouput (using the echo command) a list of names in a single column format, but the problem is the input is in row format followed by a blank space...If anyone could give me a... (2 Replies)
Discussion started by: dmhonor914
2 Replies
3. Shell Programming and Scripting
Hi,
I'm a newbie to UNIX scripting and I'm having some trouble compiling my script. I'm using the Bourne Shell and cannot seem to use the substr function correctly. I'm trying to extract the last two digits of a year that's stored in a variable based off of a condition. I've searched the... (4 Replies)
Discussion started by: E2004
4 Replies
4. Shell Programming and Scripting
Dear Bourne Shell Expert,
I am trying to change the current working directory from within a Bourne Shell script. Simply enough i thought !
As I am sure you are well aware, Inside the script i echo `pwd` and it seems ok, but the shell spawns another shell to execute this and as such, when my... (10 Replies)
Discussion started by: fawqati
10 Replies
5. Shell Programming and Scripting
Bourne: How to invoke an alias from within a shell script
If I type in the alias in the command line, it runs
If I insert that same alias into my shell script and run the shell script, the alias is not invoked.
Help please. (2 Replies)
Discussion started by: techshots
2 Replies
6. Shell Programming and Scripting
Hello all, I'm new to shell scripting and want to make a script that I can write to log the users logging on and off the a unix system.
I have had a good look over the past few days to crack it, I think I am getting close.
I want a script that runs an infinite loop to check every 5 seconds... (14 Replies)
Discussion started by: noodlesoup
14 Replies
7. Shell Programming and Scripting
Attempting to write a script to eventually notify me via email for when there is packetloss across the backbone. I am looking for values greater than 0% in the mtr field.
#!/bin/sh
target=www.google.com
date +"%D"_"%T" >> /home/rich/mtr.log
echo "----------------------------------------" >>... (1 Reply)
Discussion started by: closedown
1 Replies
8. Shell Programming and Scripting
Hi,
Get the following error when running a shell script with following statement.
Syntax error
at line 150 : `(' is not expected
150: declare -a VPO_SEV=(Normal Warning Minor Major Critical)
it runs fine using bash, so I guess the script should be using bash but is there a... (1 Reply)
Discussion started by: wilsonee
1 Replies
9. Shell Programming and Scripting
I am suppose to make a program that cuts the extension off of a file. It uses that .ext to decide which program needs to be used to open the file. This only finds the name of the program from a list of programs I made. My problem is when it has the name of the program it needs to use, how can I... (3 Replies)
Discussion started by: dordrix
3 Replies
10. Homework & Coursework Questions
This is my question, below the question is the template
Write and execute a Bourne shell script called homework that will
From within the script, create three background processes:
a) (2 points) one that saves a long listing of your hidden files to a file named hiddenlist
b) (2 points) ... (4 Replies)
Discussion started by: luislozoya
4 Replies
LEARN ABOUT PHP
gmp_setbit
GMP_SETBIT(3) 1 GMP_SETBIT(3)
gmp_setbit - Set bit
SYNOPSIS
void gmp_setbit (GMP &$a, int $index, [bool $bit_on = true])
DESCRIPTION
Sets bit $index in $a.
PARAMETERS
o $a
- The value to modify. Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string
provided that it is possible to convert the latter to a number.
o $index
- The index of the bit to set. Index 0 represents the least significant bit.
o $bit_on
- True to set the bit (set it to 1/on); false to clear the bit (set it to 0/off).
RETURN VALUES
A GMP number resource in PHP 5.5 and earlier, or a GMP object in PHP 5.6 and later.
EXAMPLES
Example #1
gmp_setbit(3) example - 0 index
<?php
$a = gmp_init("2"); //
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
gmp_setbit($a, 0); // 0b10 now becomes 0b11
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
?>
The above example will output:
2 -> 0b10
3 -> 0b11
Example #2
gmp_setbit(3) example - 1 index
<?php
$a = gmp_init("0xfd");
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
gmp_setbit($a, 1); // index starts at 0
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
?>
The above example will output:
253 -> 0b11111101
255 -> 0b11111111
Example #3
gmp_setbit(3) example - clearing a bit
<?php
$a = gmp_init("0xff");
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
gmp_setbit($a, 0, false); // clear bit at index 0
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
?>
The above example will output:
255 -> 0b11111111
254 -> 0b11111110
NOTES
Note
Unlike most of the other GMP functions, gmp_setbit(3) must be called with a GMP resource that already exists (using gmp_init(3) for
example). One will not be automatically created.
SEE ALSO
gmp_clrbit(3), gmp_testbit(3).
PHP Documentation Group GMP_SETBIT(3)