06-08-2012
Please post sample data (very important that the data includes lines containing one or more dollar character and some lines with various numbers of backslash characters) , the commands you typed, the results and any comments about what happened. I really like the idea of using the example grep lines as sample data because they seem to contain every variant.
While doing this task you will probably understand the basic concepts.
Please mention what Operating System and version you are running and what Shell you use. I can't imagine that it will be the original Bourne Shell (but it might be).
In unix fundamental commands, the dollar sign can mean the end of the line. When not escaped it introduces an Environment Variable. When double-quoted and escaped
"\$" it becomes just a dollar character. When single-quoted it is just a dollar character
'$' because single quotes disable parameter substitution. This example appears to be about teaching the fundamentals. If you use
grep to look for end-of-line characters in a normal unix text file the output will be every line.
Quote:
The first command for example, prints all lines, which I don't understand - so I suppose I must be missing on basics
In the first example the
grep is looking for end-of-line characters in a text file (i.e. line-feed characters) which are abbreviated to a dollar sign in much unix syntax. The dollar sign has been escaped with a backslash to stop it being interpreted by Shell as an introduction to an Environment Variable.
Last edited by methyl; 06-08-2012 at 05:18 PM..
Reason: multiple revisions and corrections
This User Gave Thanks to methyl For This Post:
9 More Discussions You Might Find Interesting
1. Post Here to Contact Site Administrators and Moderators
A suggetion:
Don't we need to start Java Programming in UNIX Environment Forum ? (1 Reply)
Discussion started by: cub
1 Replies
2. Shell Programming and Scripting
i have to make a menu based program to allow iusers to select the system information about their machine that they want. All i have been taught is how to enter commands at the command prompt like simple commands such as pwd and cd directory to change directory (not even sure if that is right). But... (1 Reply)
Discussion started by: carlvernon
1 Replies
3. Shell Programming and Scripting
Several months ago I found a link that explained the difference between how a Unix Systems Admin would do scripting compared to what a Unix Programmer would do.
It showed a basic script and then show several iterations that explained how the Systems Admin would change it to make it better. I was... (0 Replies)
Discussion started by: BCarlson
0 Replies
4. Programming
Hi all,
I know the basics of C programming, but I dont know a single thing about how to write, compile and run C code in UNIX, also where liberaris are stored, how .headers files are being managed in unix, how to debug c code and what are the available GNU tools for c programming in linux env,... (6 Replies)
Discussion started by: patras
6 Replies
5. UNIX for Dummies Questions & Answers
Hello,
I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies
6. UNIX for Dummies Questions & Answers
How does unix system administration, unix programming, unix network programming differ?
Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies
7. Programming
I have started reading the book Unix Network Programming, Volume 1: The Sockets Networking API. I downloaded all the source code and the readme says I must make the files.
zuro@zuro:~/book/unpv12e$ cd lib
zuro@zuro:~/book/unpv12e/lib$ make
gcc -g -O2 -D_REENTRANT -Wall -c -o... (5 Replies)
Discussion started by: xuro
5 Replies
8. Programming
I have started reading the book Unix Network Programming, Volume 1: The Sockets Networking API. I downloaded all the source code and performed all the steps present in README file.Now when i compile my first program it give the following error.
sainandan@nandan:~/unpv13e/intro$ ./daytimetcpcli... (1 Reply)
Discussion started by: bsainandan
1 Replies
9. UNIX for Beginners Questions & Answers
Let's say I have a file written in C programming
...
int
function A (Param1, Param2)
{
....
}
How to grep this function?
I tried grep -ER '^functionA(.*)/n{' filename > result.txt
Not work :mad:
Please use CODE tags on all sample input, output, and code segments; not just on shell... (4 Replies)
Discussion started by: cmdcmd
4 Replies
LEARN ABOUT DEBIAN
plan9-hoc
HOC(1) General Commands Manual HOC(1)
NAME
hoc - interactive floating point language
SYNOPSIS
hoc [ file ... ] [ -e expression ]
DESCRIPTION
Hoc interprets a simple language for floating point arithmetic, at about the level of BASIC, with C-like syntax and functions.
The named files are read and interpreted in order. If no file is given or if file is hoc interprets the standard input. The -e option
allows input to hoc to be specified on the command line, to be treated as if it appeared in a file.
Hoc input consists of expressions and statements. Expressions are evaluated and their results printed. Statements, typically assignments
and function or procedure definitions, produce no output unless they explicitly call print.
Variable names have the usual syntax, including the name by itself contains the value of the last expression evaluated. The variables E,
PI, PHI, GAMMA and DEG are predefined; the last is 59.25..., degrees per radian.
Expressions are formed with these C-like operators, listed by decreasing precedence.
^ exponentiation
! - ++ --
* / %
+ -
> >= < <= == !=
&&
||
= += -= *= /= %=
Built in functions are abs, acos, asin, atan (one argument), cos, cosh, exp, int, log, log10, sin, sinh, sqrt, tan, and tanh. The function
read(x) reads a value into the variable x and returns 0 at EOF; the statement print prints a list of expressions that may include string
constants such as "hello
".
Control flow statements are if-else, while, and for, with braces for grouping. Newline ends a statement. Backslash-newline is equivalent
to a space.
Functions and procedures are introduced by the words func and proc; return is used to return with a value from a function.
EXAMPLES
func gcd(a, b) {
temp = abs(a) % abs(b)
if(temp == 0) return abs(b)
return gcd(b, temp)
}
for(i=1; i<12; i++) print gcd(i,12)
SOURCE
/src/cmd/hoc
SEE ALSO
bc(1), dc(1)
B. W. Kernighan and R. Pike, The Unix Programming Environment, Prentice-Hall, 1984
BUGS
Error recovery is imperfect within function and procedure definitions.
HOC(1)