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 07-20-2007, 11:01 AM   #1
sancho1980
Member
 
Registered: May 2006
Location: Leipzig, Germany
Distribution: Kanotix 64
Posts: 45

Rep: Reputation: 15
shell syntax


hi

suppose i have a file called y.bin and I want to define an environment variable X and initialise it with the size of y.bin in BYTES and then export it so i can use it in the compilation of a program in which X is read and used...how do i do that? i keep getting confused with shells :-)

thanks

martin
 
Old 07-20-2007, 11:23 AM   #2
rizhun
Member
 
Registered: Jun 2005
Location: England
Distribution: Ubuntu, SLES, AIX
Posts: 268

Rep: Reputation: 47
export X=$(ls -l /path/of/y.bin | awk '{print $5}')
 
Old 07-20-2007, 11:37 AM   #3
sancho1980
Member
 
Registered: May 2006
Location: Leipzig, Germany
Distribution: Kanotix 64
Posts: 45

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by rizhun
export X=$(ls -l /path/of/y.bin | awk '{print $5}')
alright thanks!
 
Old 07-20-2007, 12:14 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Not that it probably matters much to you now but you could use a tool that's meant to output single values like "stat": "export X=$(stat -c %s /bin/ls)". If you time it you see it's (a wee bit) faster and you save executing one command.
 
Old 07-20-2007, 03:52 PM   #5
sancho1980
Member
 
Registered: May 2006
Location: Leipzig, Germany
Distribution: Kanotix 64
Posts: 45

Original Poster
Rep: Reputation: 15
Ok
I've tried to enhance that a little but it doesnt work
I was trying to use assign a processed arithmetic expression involving this file size: imagine you want X to have the value of

X := 512 - ((y.bin's size) % 512)

how can i say that??
 
Old 07-20-2007, 06:25 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Check out the "bc" command?
 
Old 07-21-2007, 07:47 AM   #7
sancho1980
Member
 
Registered: May 2006
Location: Leipzig, Germany
Distribution: Kanotix 64
Posts: 45

Original Poster
Rep: Reputation: 15
bc is not necessary i think
i just found out a couple of things... :-)
but can u explain to me why the following makefile doesnt work properly:

begin Makefile
all:
make bootdisk.bin
bootdisk.bin: 512.bin
-rm bootdisk.bin
export SECTOR_SIZE=512
touch bootdisk.bin
dd if=512.bin of=bootdisk.bin count=1 seek=0
dd if=gdt.bin of=bootdisk.bin count=$(expr $(echo $GDT_SIZE) / $(echo $SECTOR_SIZE)) seek=1
512.bin: 512.asm gdt.asm
-rm 512.bin
make gdt.bin
export GDT_SIZE=$(stat -c %s gdt.bin)
nasm -f bin 512.asm -o 512.bin
gdt.bin: gdt.asm
-rm gdt.bin
nasm -f bin gdt.asm -o gdt.bin
end Makefile

When I do "make all", I get the following output (it seems something goes wrong with exporting GDT_SIZE):

sancho@Kiste:~/assembly/boot$ make all
make bootdisk.bin
make[1]: Entering directory `/home/sancho/assembly/boot'
rm 512.bin
rm: cannot remove `512.bin': No such file or directory
make[1]: [512.bin] Error 1 (ignored)
make gdt.bin
make[2]: Entering directory `/home/sancho/assembly/boot'
rm gdt.bin
rm: cannot remove `gdt.bin': No such file or directory
make[2]: [gdt.bin] Error 1 (ignored)
nasm -f bin gdt.asm -o gdt.bin
make[2]: Leaving directory `/home/sancho/assembly/boot'
ls -l ./gdt.bin
-rw-r--r-- 1 sancho sancho 512 2007-07-21 14:18 ./gdt.bin
export GDT_SIZE=
nasm -f bin 512.asm -o 512.bin
512.asm:63: error: expression syntax error
make[1]: *** [512.bin] Error 1
make[1]: Leaving directory `/home/sancho/assembly/boot'
make: *** [all] Error 2


Do you see whats the problem here??

Thanks

Martin

Last edited by sancho1980; 07-21-2007 at 09:18 AM.
 
  


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
Shell script syntax question arash8m Programming 4 06-01-2007 09:39 AM
shell color syntax/highlighting on FC4 kz26 Linux - General 18 08-16-2005 11:07 PM
Shell Command Syntax swan2925 Linux - Software 3 06-02-2005 11:07 AM
Shell function syntax error... psyklops Programming 1 09-03-2003 02:55 AM
Shell Script Syntax dragon49 Programming 1 03-12-2003 10:25 AM


All times are GMT -5. The time now is 12:12 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