the difference between binary file and ASCII file



  • 1. Help for newbie, way to concatenate a set of files.
    Hi I am to write a shell script that concatenates a set of text files, each file has a line at top (header line) and a line at bottom (tail line) that is not to be included in the concatenated file. The concatenated file should have an extra line at bottom , containing a text representing the total number of lines in the concatenated file. HELP
  • 2. Newbie- getting the whole variable string
    File 'places' is United States of America, Planet Earth, Milky way Peoples Republic of China, Planet Earth, Milky way United Kingdom, Planet Earth, Milky way Command line " cut -f1 -d, places " will produce United States of America Peoples Republic of China United Kingdom But #!/bin/sh for name in `cut -f1 -d, places` do echo $name done Will produce United States of America Peoples How do I pass the entire name into the variable. fyi this is in bash Thanks
  • 3. Bourne; char or numbers
    hi, is there a way to find out if a variable contains characters or numbers (I'm writing a bourne shell script). This is my situation: I've got ten files containing text or numbers. Of each file I grab the first 8 bytes (cut -b1-8) and put it into a variable $i. Then..... If $i contains numbers echo "$FILE: contains numbers" If $i contains characters echo "$FILE: contains characters" thanks in advance, Greetz, Miklo
  • 4. ksh - getopts mandatory value
    I have a function defined as follows I want to make the -s and -v option mandatory. Since I couldn't find a elegant way to accomplish that, I am checking whether the ARGs are NULL for these two switches. Now, if I invoke the function as drop_view -s prince -v -t 5, I get the value of '-T" assigned to the variable viewname. [ie, if I leave the argument for -v, it is taking the switch "-t" as the value]. How would I prvent this? Thanks. function drop_view { typeset -u dbschema viewname typeset -i maxretry typeset -i RC1=8 typeset USAGE="usage: $0 -s schema -v viewname [-t max-retry]" while getopts "s:v:t:" opt do case $opt in s) dbschema=$OPTARG ;; v) viewname=$OPTARG ;; t) maxretry=$OPTARG ;; *) echo "${USAGE}" return ${RC1} ;; esac done shift $OPTIND-1 if [[ -z ${dbschema} ]]; then echo "Schema Name is mandatory" return ${RC1} fi if [ -z ${viewname} ]; then echo "View Name is mandatory" return ${RC1} fi maxretry=${maxretry:-100} echo "Schema Name : ${dbschema}" echo "View Name : ${viewname}" echo "Retry Count : ${maxretry}" } ex. when I call drop_view -s prince -v -t 5, I get the following. Schema Name : PRINCE View Name : -T Retry Count : 100
  • 5. Pipe command output to listbox
    In article <62j%c.6354$ XXXX@XXXXX.COM >, Kevin Walzer < XXXX@XXXXX.COM > wrote: . . . >I use a command syntax like "which port | port list all" as a workaround >when the command isn't showing up on my path for some reason. That puts >the full path to port in the pipe, and then the rest of the sequence >executes fine. It's helpful in other contexts, but proved redundant >here, once I fixed the errors you and Miguel pointed out. Thanks. . . . This is interesting. Kevin, while I believe I understand what you've written, I don't think it's true. I know of no circumstances in which which $APPLICATION | $APPLICATION $ARGS works around the condition that $APPLICATION does not appear in $PATH. I believe both that this misunderstands which(1), and the semantics of |. Again, if you're happy with what you have, you owe me nothing; I suggest, though, that, in the long term, deeper study of command invo- cation *in shell* might be fruitful for you.

the difference between binary file and ASCII file

Postby peter » Thu, 15 Jan 2004 17:05:37 GMT


if I have a unix shell script with permission ---x--x--x,
how can a unix shell detect that it is not an execuable binary 
application and gives an error message  "permission denied"?



Re: the difference between binary file and ASCII file

Postby those who know me have no need of my name » Thu, 15 Jan 2004 19:12:37 GMT

in i read:

on most systems an executable script must also be readable.

a signature

Re: the difference between binary file and ASCII file

Postby Carlos J. G. Duarte » Thu, 15 Jan 2004 19:25:14 GMT

That is done at kernel level. The kernel first checks your permission to 
execute some file. Then get its header and if it is a binary executable, 
run the code. Otherwise, if it is some shebang (#! path stuff) it 
actually run, in user mode, the following command "path stuff 
your-file". As the program specified by "path" tries to read the file 
before interpret it, the permission denied is issued.

file ~user/ with --x--x--x perms and contents:
#! /bin/make -f
all: ; echo all

you try: exec ~user/
kernel checks 'x' flag, ok, then loads ~user/, detects #! and try 
to run as :
$ /bin/make -f ~user/

carlos **  http://www.**--****.com/ 

Re: the difference between binary file and ASCII file

Postby Stephane CHAZELAS » Thu, 15 Jan 2004 19:55:55 GMT

2004-01-14, 08:05(+00), peter:

If it is a dynamically linked object. You can see if your
dynamic linker as options to not execute the file but instead to
write some informations about it:

on Linux: LD_DEBUG=help
(env vars)

~$ ls -l ls passwd
---x--x--x    1 chazelas users       61144 2004-01-14 09:40 ls*
---x--x--x    1 chazelas users        2260 2004-01-14 09:44 passwd*
~$ LD_TRACE_LOADED_OBJECTS=1 ./ls => /lib/ (0x40021000) => /lib/ (0x40033000) => /lib/ (0x40168000)
        /lib/ => /lib/ (0x40000000)
zsh: permission non accord: ./passwd

See your dynamic linker man page (,,
You may also play with LD_PRELOAD to override the _init or
main functions.

If the file is a valid binary file but statically linked, it
will get executed...

Sthane                      ["Stephane.Chazelas" at ""]

Re: the difference between binary file and ASCII file

Postby peter » Fri, 16 Jan 2004 04:04:25 GMT

I think there might be a loop.

with permission --x--x--x.
bash kernel will send it to system() or exec() for executing if
the file is not readable (there is a chance that the file might be 
binary). However, if it is some shebang #!/bin/bash, system() through sh 
which calls exec() will send it to bash.

Again, bash kernal cannot read this executale code, it will send it back 
to system() since bash itself cannot tell if it is binary code or not.

Not sure how shell handles this dilema.



Re: the difference between binary file and ASCII file

Postby Carlos J. G. Duarte » Sat, 17 Jan 2004 00:32:42 GMT

hi again,
there's no loop.
Using your example and some pseudo-code:

$ cat >
#! /bin/bash
echo "hi"
$ chmod 111
$ ./
[bash: exec]
[kernel: loads header, detects shebang, run /bin/bash path/]
[/bin/bash: open, permission denied]

Bash, or some other program, must open files before doing anything. You 
are confusing a "bash file" with "bash -c file". The 2nd would in fact 
cause a loop, i.e. bash was to execute file and the same mechanism would 
occur again, but the kernel actually issues the first.

carlos **  http://www.**--****.com/ 

Re: the difference between binary file and ASCII file

Postby Chris Mattern » Sat, 17 Jan 2004 11:08:31 GMT

The shell doesn't detect this.  This is a job for your
system's kernel, which the shell will shell will
call via exec().

First, the kernel checks to make sure that you do in fact
have permission to execute the file.  Then, if you do,
the kernel looks for the "#!" characters as the first
two bytes.  If it finds them, it is interpreted, and the
first line after the "#!" is the pathname of the interpreter.
The kernel loads the interpreter into memory, passing it the
name of the file as a a parameter.  If file does not begin "#!",
the kernel looks to see if the file is valid binary format
(exactly what this entails varies from system to system).  If
it is a valid binary, it loads into memory and starts it
running.  If neither begins with "#!" nor is a valid binary,
the kernel assumes it is a script for the current shell.  It
loads the current shell into memory and starts it running,
passing it the name of the file as a parameter.  Since all
this code runs in the kernel it doesn't care about your file
permissions, and that's why you can run binary programs you
can't read.  But with interpreted files, the kernel actually
loads the interpreter.  The interpreter runs as user code,
so it must have permission to read the script.

             Chris Mattern

Similar Threads:

1.Binary File Differences: When Do Differences Matter?

We will soon be building our software system on new hardware (same make/model, 
just new boxes).  I have noticed that even on our existing hardware, building 
the exact same software from the same source will give differing binary files, 
some even with minor file size differences.  So now, when we move over to the 
new hardware, how can we be sure that we are still building the same software 
given that the binaries contain differences even without changing systems?  Of 
course, we will be completely testing the software built on the new system.  Is 
there any way to tell if the differences in the binary files are differences 
that will affect the actual operation of the software, or perhaps the ability to 
update a single dynamic library?  I'd like to be able to do some kind of 
checkout other than the full system test to give me some confidence that the new 
hardware is building the same system as the old hardware.  Any suggestions?

2.what is the difference between binary and rom files

i found somewhere a line mentioning that the user has a choice between
rpm and binary files

what is the difference between the two  ( some rpm packege for the
mysql server  software )

3.Append image file to ASCII text file

I'm looking for a way on the Linux command line be be able to append
an image file to an ASCII text file.  One thought I had was to first
convert the text file into postscript and then append the signature
image to that file.

# Convert ascii file to postscript
enscript file.txt --no-header -o

# Append both image files into one
convert -append image.bmp file_with_image.pdf

This sort of worked, but only part of the text file and image are
viewable in the new pdf file so I'm looking for a better solution.
The text file is a check that will be printed on a HP laser printer
and the image is a signature to be printed on the bottom of the
check.  Does anyone have any suggestions on how I can do this?

4.Assigning contents of a ascii file to a script variable but maintain file structure

How do  I  assign the results of sed or grep to a shell variable but
maintain its format.

If I have a ascii file named sumdarnfil


At the command line I run

grep "2$" sumdarnfil

the results are
vidalc 31349: grep "2$" sumdarnfil

If I

tmpfile=`grep "2$" sumdarnfil
echo $tmpfile

the result is
 vidalc 31350: tmpfile=`grep "2$" sumdarnfil`
vidalc 31351: echo $tmpfile
a2 z2 b2 j2

For practical purposes echo $tmpfile | tr ' ' '\012' isnt a good option.

5.difference between normal file and named pipe file

        will anyone let me know the differences between the normal unix
file and named pipe file?


6. all files show differences with Unix files

7. File size difference when nulling a file

8. convert text file to binary excel file

Return to unix


Who is online

Users browsing this forum: No registered users and 34 guest