473,508 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shell script

5 New Member
So im working on a lab for my unix class and im having some problems with this shell script we are supposed to do here is the question: Write a shell script that accepts a list of files(space delimited), and does the following 1)lists a long listing of the file
2) displays the number of lines in the file
3) displays the first 2 lines of the file
4) after listing all files, displays a friendly goodbye message.
separate the files with some dashes and make it easy to read.
heres my script:

#!/bin/bash

while [ "$1" != "" ]
do

ls -la$1
shift

wc
shift

head-n2
shift

echo goodbye
done

exit 3

now he gave an example in class thats like this:

#!/bin/bash

# This is a Comment Line
while [ "$1" != "" ]
do
ls -la $1
shift
done

exit 0

he said that this shell script is basically this but i had to add in the other commands besides the long listing. any help will be great. thanks
Feb 14 '08 #1
1 2565
WinblowsME
58 New Member
heres my script:

#!/bin/bash

while [ "$1" != "" ]
do

ls -la$1
shift

wc
shift

head-n2
shift

echo goodbye
done
You're on the right track. Everytime you use shift, your command-line arguments are shifted to the left. So, if the name of your script is test_script and you run the script with the following arguments test_script A B C D, $1 will be A, and if you use shift, A will be shifted out and $1 will become B, and so forth... Also, you might want to check out the man page for the wc command. I'm pretty sure you need to use an option to list the line count.
Feb 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5653
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info...
3
3693
by: FPGA05 | last post by:
Hello All, I am developing a small application in which I would need a C++ application to read the output from a shell script. A shell script keeps looking for user inputs and once the user...
6
8461
by: Sanket80 | last post by:
Hi, I have one shell script which runs a report and sends the output to user. The shell script has some queries written in it in SQL and hence when I execute a shell script via a concurrent...
9
78187
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell...
3
5437
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I...
2
3466
by: ellennolan | last post by:
Hello, I wonder if anyone can help with calling external shell script in c++. Basically, in the shellscript, I want to pass src, dst, md5. If the src's md5 matches md5 given, it will be link to...
5
2145
by: Hul Tytus | last post by:
comp.lang.c c programs & shell conditionals How is a unix shell script made to respond to the value returned by a program compiled from c code? The shell script below is my current effort,...
5
5066
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
7
6204
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
4
34271
by: devi thapa | last post by:
Hi, I am executing a python script in a shell script. The python script actually returns a value. So, can I get the return value in a shell script? If yes, then help me out. Regards, Devi
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.