LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2004, 11:07 AM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Need help in explaining Bash code


The code below is stored in a file named
/home/bash_script

1) When I run the program bash_script, it did not did
list all files and directory in argument two ($2) which is
/usr/suid, but instead it list the files and directory in
/home/

2) On the code abc /usr/suid "$2", I change it to
abc /usr/suid "$1", but it did not changed anything.

3) The code abc /usr/suid "$2" . Does it means to
call the function abc whereas usr/suid is passed as
a second argument ?
========================

Code:
#!/bin/bash

function abc()
{
   ls -al $2
}

abc /usr/suid  "$2"
 
Old 07-08-2004, 11:24 AM   #2
SheldonPlankton
Member
 
Registered: Jun 2004
Posts: 129

Rep: Reputation: 15
I think you want ...
Code:
#!/bin/bash
function abc() {
ls -al $1
}

abc /usr/suid

Last edited by SheldonPlankton; 07-08-2004 at 11:25 AM.
 
Old 07-08-2004, 01:03 PM   #3
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply

Hi SheldonPlankton, and thank you for your help.
What does the statement abc /usr/suid "$2" do ?
Does it passed an external argument number two to the function abc ?

function abc()
{
ls -al $2
}

abc /usr/suid "$2"
 
Old 07-08-2004, 07:18 PM   #4
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Yeah, but as you have no argument 2 it would just call 'ls -al' (hence it's operating on the current directory)
 
Old 07-09-2004, 10:50 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Well, you may have an argument 2 if you pass it to the original script:

$ bash_script unused_arg1 arg2

That would lead to execute:

ls -al arg2
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Doubt with a bash code linuxlover1234 Programming 10 03-30-2004 12:48 PM
stripping of bash code? Lindows45 Linux - Newbie 2 03-01-2004 07:51 AM
bash code cursor left/right collen Programming 1 01-19-2004 03:36 PM
where is the bash source code?... gearoid Programming 5 11-25-2003 04:24 AM
Bug in c code calling bash code Linh Programming 11 08-12-2003 04:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration