Help with bash shell scripting

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help with bash shell scripting
# 8  
Old 04-12-2011
Well, there are many ksh clones out there, but ksh93 is free. It works in my 1988 HPUX 11_00 ksh. It even works in my 1988 sh:
Code:
$ sh -c 'k=1 ; (( k += 5 )) ; echo $k'
6
$

# 9  
Old 04-12-2011
Yes,
as far as I know it works with all Korn Shell variants,
I'm only saying that it's not POSIX.

Code:
zsh-4.3.11[radoulov]% ksh -c '((x=x+3)); echo $x'
3
zsh-4.3.11[radoulov]% mksh -c '((x=x+3)); echo $x'
3
zsh-4.3.11[radoulov]% pdksh -c '((x=x+3)); echo $x'
3
zsh-4.3.11[radoulov]% ash -c '((x=x+3)); echo $x'

zsh-4.3.11[radoulov]% dash -c '((x=x+3)); echo $x'

zsh-4.3.11[radoulov]% posh -c '((x=x+3)); echo $x'

zsh-4.3.11[radoulov]%

---------- Post updated at 09:56 PM ---------- Previous update was at 09:53 PM ----------

Quote:
Originally Posted by DGPickett
It works in my 1988 HPUX 11_00 ksh. It even works in my 1988 sh:
Code:
$ sh -c 'k=1 ; (( k += 5 )) ; echo $k'
6
$

It works on HP-UX because its /usr/bin/sh is ksh88.
Try it with /bin/sh on Solaris Smilie
# 10  
Old 04-12-2011
I suspected something such, as the sh executable is separate, bigger and newer.

I can never sort out the culture wars between POSIX, AT&T SVR?, LINUX, GNU, BSD and all the prop. players: AIX, Solaris, HP-UX, ???? I know they keep changing the regex, so I have to worry about which library path which program runs under. I want my \< and \> back!
# 11  
Old 04-12-2011
Yes,
they are different Smilie

Regarding the shell, Sven Mascheck maintains a great site,
there is page dedicated to the various system shells:

www.in-ulm.de/~mascheck/various/shells/
# 12  
Old 04-12-2011
It'd be neat to chart them and their sometimes shared idiosyncracies! I should google for it! Smilie
# 13  
Old 04-12-2011
Quote:
Originally Posted by Corona688
You also missed my point about k vs $k inside (( )). ((k=k+3)) works, (($k=$k+3)) does not since K gets substituted before anything starts calculating, so you end up trying to assign the value of 3 or something. Just plain variable names don't ever need a $ inside a (( )) expression anyway, why make them more complicated?
Well k is not guaranteed to behave the same way as $k inside an integer expression. It depends on the content of k. Example:
Code:
$
$
$ a="2+2"
$ b="3+3"
$ ((c = a * b )) ; echo $c
24
$ ((c = $a * $b )) ; echo $c
11
$

Returning to original question... Here is one way to get a number...
Code:
$ cat getn
#! /usr/bin/ksh

printf "Enter a number - "
read number

printf "you entered %d \n" $number

exit 0

$
$
$ ./getn
Enter a number - 77
you entered 77
$

I think you should be able to expand it to get 2 numbers. And you seem to have a complete discussion on adding them. Smilie
# 14  
Old 04-12-2011
Doesn't get it outside, k=$(( $k + 3 )), so that is not an issue.

I like 11 as the right answer, so $ is necessary? Mult takes precedence over + ? Or left to right, it should be 15. Ugly! I always use paren. no priority applicable.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Learn bash shell scripting

I do not know shell scripting. But at work place, I have got an in and out shell scripting task. I just need to understand a very big script. Is there any tool in which I can place the script and it can tell me the meaning of the whole script? (3 Replies)
Discussion started by: lg123
3 Replies

2. UNIX for Dummies Questions & Answers

BASH Shell Scripting: If, Then Statement

I'm having trouble trying to create a BASH shell script. I want the user to input a command "cat file_name.c" and then the shell script will delete all comments "/* */" from file_name.c else exit. So far I have this: #!/bin/bash read "cat file" // User will input command cat... (7 Replies)
Discussion started by: inkjoy00
7 Replies

3. Shell Programming and Scripting

Bash shell scripting doubt

Hello All, I am setting up a cron job, where i am calling a shell script to make few builds. I got struck at a point, need some expert inputs to proceed further. The script is categorized in 5 parts and in the last part while building software it asks for few questions like:- 1. Build mode... (4 Replies)
Discussion started by: sahil_jammu
4 Replies

4. UNIX for Dummies Questions & Answers

File handling in bash shell scripting

i am new to shell scripting and stuck at one place in my program. i am reading data from one structured file and extracting some data from particular lines and then writing into the output file. In that reading input file line by line from while loop. while read line do rectype=line... (7 Replies)
Discussion started by: reeta_shri
7 Replies

5. Shell Programming and Scripting

bash shell scripting error need help urgently

#! /bin/sh abcd = "Hello world" if then echo $abcd fi i got error message that line3 : abcd: command not found line5 : [0: command not found line5 : [1: command not found i have no idea why i got this message. Can some one help me ??? (6 Replies)
Discussion started by: bonosungho
6 Replies

6. Shell Programming and Scripting

File handling with bash shell scripting

Hi all, Can anyone guide to get tricks for file handling in bash shell? Thanks in advance. Thanks Deepak (2 Replies)
Discussion started by: naw_deepak
2 Replies

7. Shell Programming and Scripting

how to use regular expression in Bash Shell Scripting

Hi, Actually i have written one test.sh (shell program) in bash. Here i have a variables $a which stored the value package1. Now I want to write a regular expression inside the if command that "if $a variable contains letter p in the begining of the value package1 then it is coming true.... (5 Replies)
Discussion started by: sunitachoudhury
5 Replies

8. Shell Programming and Scripting

Bash shell Scripting help

wwww wwwwwwww wwwwwwwwwwwww (0 Replies)
Discussion started by: keyvan
0 Replies

9. Shell Programming and Scripting

Help!! bash shell scripting..

Can any1 please help me... i'm really lost in using bash shell scripting... and i got to hand this up on monday... please anyone teach me how to do this assignment... Please use basic things because i just learn the program only... thanks ... (1 Reply)
Discussion started by: Fr0z3n999
1 Replies

10. Shell Programming and Scripting

bash shell scripting

Hi, i am new to UNIX. I have couple of basic questions. 1. Is the syntax for BASH shell programming same in the LINUX and SUN SOLARIS operating systems? 2. I have to work on BASH shell programming in SUN SOLARIS operating system. I am going through the documentation from the following... (4 Replies)
Discussion started by: azazalis
4 Replies
Login or Register to Ask a Question