LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-03-2008, 08:36 AM   #1
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Rep: Reputation: 15
shell scripting/ the fc -l command !


i wrote the following program:

# !/bin/bash
#profile program
function histoire {
HISTSIZE=20
echo “HISTSIZE est égale à” $HISTSIZE
echo “le numéro de la commande est” $fc $-l
}
histoire
exit 0

can someone tell me, why am i not getting the same result, as in when i directly write the command fc -l ? and whats hBl ?

knoppix@knoppix:/ramdisk/home/knoppix/tmp$ chmod +x .profile
+ chmod +x .profile
knoppix@knoppix:/ramdisk/home/knoppix/tmp$ ./.profile
+ ./.profile
HISTSIZE est égale à 20
le numéro de la commande est hBl
 
Old 01-03-2008, 08:44 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
where did you read that "$fc $-l" would do what you want? that means nothing.... try "$((fc -l))" instead.
 
Old 01-03-2008, 08:49 AM   #3
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
well after trying $(fc -l )
the only thing that wouldnt give me errors was $fc$-l !!

i tried $((fc -l)), but that gives me 0, i want the same list that i get when i simply type fc -l on the xterm !

how can i do that? any idea ?
 
Old 01-03-2008, 08:55 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
yeah it does doesn't it? retard alert.... i knew it didn't look right... sorry, it does basic expression evalution...

# echo $(( 10 + 10 ))

20

you do need $(fc -l) or `fc -l` to actually execute fc as a command. i don't think that that's really useful to you though as it'll print it all on one line... i'd just put the fc command on a new line by itself.



doh!

Last edited by acid_kewpie; 01-03-2008 at 09:18 AM.
 
Old 01-03-2008, 09:01 AM   #5
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
neither 'fc -l' nor $(fc -l) worked !
i already tried those two,
maybe i should add some argument or sthg? i cant get the answer that i want,

$(fc -l) gives me hBl as an answer !!
and 'fc -l' gives me fc -l as an answer !!
 
Old 01-03-2008, 09:03 AM   #6
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
actually $fc $-l gives me hBl as an answer
$(fc -l) gives me nth as an answer !!
 
Old 01-03-2008, 09:18 AM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
no it's `fc -l` not 'fc -l' but as above i don't think you should use that mechanism at all, just run it normally outside of echo.
 
Old 01-03-2008, 09:38 AM   #8
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
what do you mean by outside of echo ?

i have this program:i changed the fc -l command :

# !/bin/bash
#profile program
function histoire {
HISTSIZE=20
echo “HISTSIZE est égale à” $HISTSIZE
echo “le numéro de la commande est” `fc -l`
}
histoire
exit 0

BUT I GET NOTHG AS AN ANSWER !
 
Old 01-03-2008, 09:42 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
# !/bin/bash
#profile program
function histoire {
HISTSIZE=20
echo “HISTSIZE est égale à” $HISTSIZE
echo “le numéro de la commande est”
fc -l
}
histoire
exit 0
 
Old 01-03-2008, 09:53 AM   #10
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
this also gives me "nthg" as an answer !
 
Old 01-03-2008, 09:54 AM   #11
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
do you atually mean "nothing"...? or literally a text string as you wrote?? if fc -l doesn't give you an output, then you have no recorded history to output...
 
Old 01-03-2008, 10:08 AM   #12
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
yes i actually mean nthg, just blank space ,
i have a recorded history to output, and i know that because when i type fc -l in my xterm then i get a long list !!
 
Old 01-03-2008, 07:38 PM   #13
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 75
Quote:
Originally Posted by mayaabboud View Post
can someone tell me, why am i not getting the same result, as in when i directly write the command fc -l ? and whats hBl ?
Both of these questions have simple explanations. First, let’s see what fc does (taken from here):
Quote:
Originally Posted by The Open Group Base Specifications Issue 6
The fc utility shall list, or shall edit and re-execute, commands previously entered to an interactive sh.
As you can see, fc only works (or should only work) on an interactive shell (i.e., one in which you can interactively type commands).

For example, consider this simple program (which I will save in a text file named program):
Code:
#!/bin/sh

fc -l
Now, watch what happens when I try to execute it as a script:
Code:
$ chmod +x program
$ ./program
$
And watch what happens if I source it into my interactive shell:
Code:
$ source program
1         cd /tmp
2         cat > program
3         chmod +x program 
4         ./program
$
As for “hBl”, this is the result expanding “$-l” in a script. You see, it shall be parsed as “${-}l” where the internal variable $- has the flags currently set (this is a ksh-ism borrowed by bash). In this case, the flags set are for brace expansion and command hashing.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
goto/label command for scripting in bash shell terry.trent Linux - Software 3 07-09-2010 11:15 AM
shell scripting problem, sed command kamkos Linux - General 5 03-31-2007 10:39 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
Shell Scripting - use the output of a command as an argument for another timgiffney Programming 6 04-17-2006 12:13 PM
command line options for firefox for shell scripting. dr_zayus69 Programming 1 05-25-2005 12:36 PM


All times are GMT -5. The time now is 02:16 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration