USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

shell scripting
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming
View previous topic :: View next topic  
Author Message
99rake99
New Member


Joined: 22 Dec 2024
Posts: 1
Location: NY

PostPosted: Tue Dec 22, 2024 11:54 pm    Post subject: shell scripting Reply with quote

hi ,

I need to write a shell script for the following requirement . its very urgent plz help mee..
Need to write shell script and it needs accept 4 arguments

4 argument need to pass to main shell script.
If 1st argument is ucsr

call Ucsr.sh (in that ucsr.sh anything doesnt matter 2nd 3rd 4th)

Else if 1st argument is ssp

call Ssp.sh ( in that ssp.sh anything doesnt matter 2nd 3rd 4th)

elseif if 1st argument is ucsr_final

call Ucsrfinal.sh (in that ucsrfinal.sh anything doesnt matter 2nd 3rd 4th)

else if 1st argument is fttp

call fttp.sh (in that ucsr.sh anything doesnt matter 2nd 3rd 4th)

2nd argument should take a table name

3rd argument contractor name ( should be a character)

4th argument a sequence number (should be a number)


thanks in advance..


Back to top
View user's profile Send private message
Germ
Keeper of the BIG STICK


Joined: 30 Apr 2024
Posts: 12452
Location: Planet Earth

PostPosted: Wed Dec 23, 2024 1:12 am    Post subject: Reply with quote

Having trouble with your home work?



_________________
Laptop: Mandriva 2024 PowerPack - 2.6.33.5-0.2mnb
Desktop: Mandriva 2024 Free - kernel 2.6.33.2-1mib
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Wed Dec 23, 2024 1:36 am    Post subject: Reply with quote

here are some links that should help you out.

Bash basics from FAQ.org: http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html

About.com - Bash for beginners: http://linux.about.com/od/bgb_guide/Bash_Guide_for_Beginners.htm

bash Scripting Basics fro ghacks.net: http://www.ghacks.net/2009/05/20/get-to-know-linux-bash-scripting-basics/

The Linux Documentation Project:
* Bash Programming Intro: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
* Bash Guide for beginners: http://tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf
* Bash Scripting Advanced Guide: http://tldp.org/LDP/abs/html/

For even more helpful bash links... Let Me Google That for You

Good luck on your homework!



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
exiled
Jr. Member


Joined: 24 Nov 2024
Posts: 51
Location: ~/

PostPosted: Wed Dec 23, 2024 3:27 am    Post subject: Reply with quote

Yes this does looks like homework.

If it's not homework then I suggest you use
Python which is much better suited to this
type of object oriented structure. Wink



_________________
Currently: Frugalware, Fedora
Previously: Gentoo, Startcom, Debian, Sabayon, Mint, openSUSE, Mangaka Chu, #!CrunchBang
Back to top
View user's profile Send private message
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Wed Dec 23, 2024 3:40 am    Post subject: Reply with quote

For a simple script like that Python would be a bit overkill...

Bash is more than capable of parsing arguments and then executing the appropriate script in response. It can be done in python but Bash is easier.

Bash version (assuming the called scripts handle their own error conditions):
13 lines
19 "words"
152 characters

Python? not implemented but i guarantee larger than that.



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
exiled
Jr. Member


Joined: 24 Nov 2024
Posts: 51
Location: ~/

PostPosted: Wed Dec 23, 2024 10:34 am    Post subject: Reply with quote

It's not about how many words
to accomplish an elif block...

Most likely you can turn 5 individal shell scripts
into 1 Python program.
Each of the 4 call scripts now become a class.

It looks like an object oriented structure to me
and if it's not "shell script homework" then Python
is probably better suited to the task (IMHO).
Of course I have no idea what code the call scripts
contain, but I'm sure Python can reproduce their functionality.

Tomato - Tomoto Wink



_________________
Currently: Frugalware, Fedora
Previously: Gentoo, Startcom, Debian, Sabayon, Mint, openSUSE, Mangaka Chu, #!CrunchBang
Back to top
View user's profile Send private message
VHockey86
Advanced Member


Joined: 12 Dec 2024
Posts: 988
Location: Rochester

PostPosted: Wed Dec 23, 2024 11:28 am    Post subject: Reply with quote

Lord.DragonFly.of.Dawn wrote:
For a simple script like that Python would be a bit overkill...

Bash is more than capable of parsing arguments and then executing the appropriate script in response. It can be done in python but Bash is easier.

Bash version (assuming the called scripts handle their own error conditions):
13 lines
19 "words"
152 characters

Python? not implemented but i guarantee larger than that.


Admittedly I don't understand what he wanted done with the 2nd,3rd,4th arguments...but the rest is a trival 4 line script, 3 if you don't count imports.
If they're supposed to be passed to the other script then its essentially the same thing just with a string formatting statment inside the system call.
Code:

import sys,os
script_map = {'ucsr':'Ucsr.sh', 'ssp':'Ssp.sh', 'ucsr_final':'Ucsrfinal.sh','fttp':'fttp.sh'}
table,contractor,number = sys.argv[2:5]
os.system(script_map[sys.argv[1]])



_________________
Main Desktops : Kubuntu 10.4. ArchLinux 64-bit. Windows7 64-bit. Windows XP 32-bit.

MacBook: OS X Snow Leopard (10.6)
Back to top
View user's profile Send private message
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Wed Dec 23, 2024 10:31 pm    Post subject: Reply with quote

hmm.... okay, shorter than I had expected....



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Thu Dec 24, 2024 12:38 am    Post subject: Reply with quote

pfffffffft how many lines ....really? A shell script CAN all be on ONE line, doesn't mean it SHOULD be.

The OP ask about shell scripting, sort of rude to ask him to use a whole different language just because you prefer it. Now before you start complaining, there are so many languages that can be used with Linux, that I GUARANTEE you that a perl guru would argue that it is best done in perl, a ruby guru ruby, etc etc etc.

And those of you that think shell scripting is inferior to all other languages ...... BAH, I am very proficient in shell scripting, and can do things with bash you wouldn't believe a shell script can do. I have written many shell scripts that exceed 500 lines, and they are commented well, and EASY to maintain. jbsnake is the bash guru though, and i've seen him write stuff so fast it will make your head spin, and routinely writes shell scripts that work in place of other languages like perl/python etc....... sometimes, it's just what you know best. He has working solutions before the programmers have even started coding Wink Since I am more of a procedural coder, (but am trying to master python Wink ) I love the shell.

Obviously this was homework Wink
So to the OP, if you EVER come back ... good luck with your homework, we can HELP you, but no one will do your work for you. You won't learn anything that way Razz



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
exiled
Jr. Member


Joined: 24 Nov 2024
Posts: 51
Location: ~/

PostPosted: Thu Dec 24, 2024 1:14 am    Post subject: Reply with quote

crouse wrote:
pfffffffft how many lines ....really? A shell script CAN all be on ONE line, doesn't mean it SHOULD be.

The OP ask about shell scripting, sort of rude to ask him to use a whole different language just because you prefer it.

Did you say rude? Yes that would be me. (Ha! Ha! Ha!)

Actually, I prefer tcl over bash and bash over python,
but your correct homework boy did say shell script, so
I'll keep my superior suggestions to myself. Razz

I am kidding... There is no way I can't keep suggestions to myself Laughing

good thread Very Happy



_________________
Currently: Frugalware, Fedora
Previously: Gentoo, Startcom, Debian, Sabayon, Mint, openSUSE, Mangaka Chu, #!CrunchBang
Back to top
View user's profile Send private message
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Thu Dec 24, 2024 2:56 am    Post subject: Reply with quote

crouse wrote:
pfffffffft how many lines ....really? A shell script CAN all be on ONE line, doesn't mean it SHOULD be.

-snip-

And those of you that think shell scripting is inferior to all other languages ...... BAH, I am very proficient in shell scripting, and can do things with bash you wouldn't believe a shell script can do. I have written many shell scripts that exceed 500 lines, and they are commented well, and EASY to maintain. jbsnake is the bash guru though, and i've seen him write stuff so fast it will make your head spin, and routinely writes shell scripts that work in place of other languages like perl/python etc....... sometimes, it's just what you know best. He has working solutions before the programmers have even started coding ;) Since I am more of a procedural coder, (but am trying to master python ;) ) I love the shell.


I should have qualified....

the bash script was spaced in a readable way (although lacking comments) and was extremely simple.

As for bash coding... Did you know you can do audio postprocessing in bash using read, arrays, exho, and bc?

just because you can doesn't mean you should. that monsterous 1000 line bash script duplicated about a tenth of a tenth of a percent of the functionality of SoX and was not portable (it relied on the behavior of a SPECIFIC audio card driver version, to the point that a kernel update broke it) and was a nightmare to read.

on the other hand you can do pretty amazing things with it too, like writing an auto DJ, automating the remastering of audiobooks (using SoX, normalize and others like it should do), and thousands of other tasks.

of course i'm not aware of a single linux distribution that doesn't rely heavily on bash scripts for system boot.



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
platinummonkey
Advanced Member


Joined: 01 Mar 2024
Posts: 732
Location: Texas

PostPosted: Thu Dec 24, 2024 4:39 am    Post subject: Reply with quote

Lord.DragonFly.of.Dawn wrote:
of course i'm not aware of a single linux distribution that doesn't rely heavily on bash scripts for system boot.


... you shouldn't tempt me Razz lol



_________________
desktop - FreeBSD 7.2
laptop & server - Archlinux i686 kernel26 2.6.32.10-1
- TAMULinux-2.0.2-ALPHA
USB Boot - Archlinux i686 kernel26 2.6.32.10-1 USB boot
Back to top
View user's profile Send private message Visit poster's website AIM Address
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Thu Dec 24, 2024 4:49 am    Post subject: Reply with quote

platinummonkey wrote:
Lord.DragonFly.of.Dawn wrote:
of course i'm not aware of a single linux distribution that doesn't rely heavily on bash scripts for system boot.


... you shouldn't tempt me :P lol


please do prove me wrong. I'd love to get to know some of the more esoteric distributions.



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Thu Dec 24, 2024 5:06 am    Post subject: Reply with quote

Lord.DragonFly.of.Dawn wrote:
of course i'm not aware of a single linux distribution that doesn't rely heavily on bash scripts for system boot.


Pardus (i think it uses python)...not positive, and i think slackware had some replacement type scripts for some things...but it's been awhile since i've played with slack.


The only bane of shell scripting for me is the speed differences between the shell and other languages. It's not uncommon for me to have to parse thousands of documents , and while perl is MUCH faster, I've been working on learning python, which is probably not as fast as perl, but close.



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Thu Dec 24, 2024 12:19 pm    Post subject: Reply with quote

yeah... spawning subshells, which happens a *LOT* in shell scfipting, is not the cheapest of operations...

that's bitten me quite a few times before.



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse