You are not logged in.

#1 2004-06-18 22:14:11

iotc247
Member
From: Florida
Registered: 2004-05-31
Posts: 177
Website

Bash

If i make a script in bash how do i make it so that theres 2 parts and the second part must be executed with scriptname -argument and i also want to have --help

Offline

#2 2004-06-18 22:43:09

iotc247
Member
From: Florida
Registered: 2004-05-31
Posts: 177
Website

Re: Bash

anyone..

P.S just trying to get the forum to be bright for  people to help cause it aint lit to me..

Offline

#3 2004-06-18 22:53:28

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Bash

It only becomes lit when a post is new relative to the reader's last vist. So if anybody comes that hasn't seen the post it will be lit.

I don't understand the question fully. You can access a second file using

source filename

in the script.

You can access the parameters entered to the script using $1 for the first parameter, $2 for the second, etc. (the first parameter is the script name) if there are more than 9 parameters, look into the shift operator.

There's some links in the Arch WHERETO in the wiki to sites that teach you basic and advanced bash. You should have looked there first and searched google.

Dusty

Offline

#4 2004-06-18 22:58:53

iotc247
Member
From: Florida
Registered: 2004-05-31
Posts: 177
Website

Re: Bash

What i meant was if i just type in filename because its executable and in /usr/bin/ it will show somewhat like just typing pacman would.. And then filename -c would do one thing filename -r would do another and so on..

Offline

#5 2004-06-18 23:09:11

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Bash

put #!/bin/sh as the first line with no whitespace before it.

then chmod a+x filename.

then you should be able to execute with ./filename.

put it in /usr/bin or anywhere in the path to executable.

Offline

#6 2004-06-18 23:13:52

iotc247
Member
From: Florida
Registered: 2004-05-31
Posts: 177
Website

Re: Bash

i know that i need to know how to make it be able to do command -c or command -d like command will just show basically what pacman does.. command -h will show the help and command -d will do something else and so on..

Offline

#7 2004-06-18 23:33:55

iotc247
Member
From: Florida
Registered: 2004-05-31
Posts: 177
Website

Re: Bash

Is there an easier way than doing if [ $1 = -h ]; then throughout the file but and at the end of the section end with an fi? Anyways now all i get is a

/usr/bin/kernel: line 4: [: =: unary operator expected
/usr/bin/kernel: line 23: [: =: unary operator expected
/usr/bin/kernel: line 115: [: =: unary operator expected
 how do i stop that..

Offline

#8 2004-06-18 23:38:10

iotc247
Member
From: Florida
Registered: 2004-05-31
Posts: 177
Website

Re: Bash

Thx for that link in the wiki.. but cant stop those problems

Offline

#9 2004-06-18 23:53:14

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: Bash

what you are looking for is getopt and getopts..
most languages have these utilities (perl, php, etc.).
Bash does too..
http://www.aplawrence.com/Unix/getopts.html


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

Board footer

Powered by FluxBB