Sponsored Content
Full Discussion: scope of the variable - Naga
Top Forums Shell Programming and Scripting scope of the variable - Naga Post 302310932 by nagnatar on Monday 27th of April 2009 11:02:02 AM
Old 04-27-2009
for better understanding

# more add.sh
i=0
while read line
do
k=`expr $i + $line`
i=$k
done < num
echo "Final : ${i}"


# sh add.sh
Final : 0 -------------> Here is my question..why sh gives zero as output when bash, and ksh gives correct output

# ksh add.sh
Final : 20

# bash add.sh
Final : 20
 

10 More Discussions You Might Find Interesting

1. Programming

C++ variable scope and mutexes

I've been wondering if I can make mutexes much easier to use in C++ with creative use of a locking class and variable scope, but I'm not sure if things happen in the order I want. Here's pseudocode for something that could use the class: int someclass::getvalue() { int retval; ... (0 Replies)
Discussion started by: Corona688
0 Replies

2. Shell Programming and Scripting

problem with shell variable's scope

Hi, I am stuck while developing a shell sub-routine which checks the log file for "success" or "failure". The subroutine reads the log file and checks for key word "success", if found it set the variable (found=1). It returns success or failure based on this variable. My problem is, I can... (2 Replies)
Discussion started by: cjjoy
2 Replies

3. Shell Programming and Scripting

variable scope

Hi, I want to know about the variable scope in shell script. How can we use the script argument inside the function? fn () { echo $1 ## I want this argument should be the main script argument and not the funtion argument. } also are there any local,global types in shell script? if... (3 Replies)
Discussion started by: shellwell
3 Replies

4. Shell Programming and Scripting

[SOLVED] Scope of KSH Variable in Perl?

cat test.ksh #!/usr/bin/ksh VAR="Dear Friends \n How are you? \n Have a nice day \n" export VAR echo "Inside test.ksh"; ./test.pl cat test.pl #!/usr/bin/perl print "Inside test.pl \n"; print "$VAR"; Output: ./test.ksh Inside test.ksh Inside test.plWhat I want to achieve is, I... (1 Reply)
Discussion started by: dahlia84
1 Replies

5. UNIX for Dummies Questions & Answers

Bash loops and variable scope

Hi All, I've been researching this problem and I am pretty sure that the issue is related to the while loop and the piping. There are plenty of other threads about this issue that recommend removing the pipe and using redirection. However, I haven't been able to get it working using the ssh and... (1 Reply)
Discussion started by: 1skydive
1 Replies

6. Shell Programming and Scripting

Help with retaining variable scope

Hi, I use Korn Shell. Searched Forum and modified the way the file is input to the while loop, but still the variable does not seem to be retaining the final count. while read name do Tmp=`echo $name | awk '{print $9 }'` Count=`cat $Tmp | wc -l`... (6 Replies)
Discussion started by: justchill
6 Replies

7. Shell Programming and Scripting

Variable scope in bash

Hello! Before you "bash" me with - Not another post of this kind Please read on and you will understand my problem... I am using the below to extract a sum of the diskIO on a Solaris server. #!/bin/sh PATH=/usr/bin:/usr/sbin:/sbin; export PATH TEMP1="/tmp/raw-sar-output.txt$$"... (3 Replies)
Discussion started by: haaru
3 Replies

8. Shell Programming and Scripting

Maintain Scope of the variable in UNIX

Hi All Is there is any way to maintain the scope of the variable in unix Example x=1 j=1 while do .. .... .... while do .. .. x=x+1 done #inner most while loop ends here done #outer loop ends here (8 Replies)
Discussion started by: parthmittal2007
8 Replies

9. Shell Programming and Scripting

BASH: variable and function scope and subscripts

Hi, I'm a Delphi developer new to linux, new to this forums and new to BASH programming and got a new task in my work: maintaining an existing set of BASH scripts. First thing I want to do is making the code more reliable as in my opinion it's really bad written. So here's the quest: I'm... (6 Replies)
Discussion started by: rse
6 Replies

10. Programming

Variable Scope in Perl

I have to admit that i have not used Perl at all and this is a singular occasion where i have to patch an existing Perl script. I dearly hope i do not have to do it again for the next 15 years and therefore try to avoid having to learn the programming language in earnest. The OS is AIX 7.1, the... (2 Replies)
Discussion started by: bakunin
2 Replies
blowfish(n)						       Blowfish Block Cipher						       blowfish(n)

__________________________________________________________________________________________________________________________________________________

NAME
blowfish - Implementation of the Blowfish block cipher SYNOPSIS
package require Tcl 8.4 package require blowfish ?1.0.4? ::blowfish::blowfish ?-mode [ecb|cbc]? ?-dir [encrypt|decrypt]? -key keydata ?-iv vector? ?-out channel? ?-chunksize size? ?-pad padchar? [ -in channel | ?--? data ] ::blowfish::Init mode keydata iv ::blowfish::Encrypt Key data ::blowfish::Decrypt Key data ::blowfish::Reset Key iv ::blowfish::Final Key _________________________________________________________________ DESCRIPTION
This package is an implementation in Tcl of the Blowfish algorithm developed by Bruce Schneier [1]. Blowfish is a 64-bit block cipher designed to operate quickly on 32 bit architectures and accepting a variable key length. This implementation supports ECB and CBC mode blowfish encryption. COMMANDS
::blowfish::blowfish ?-mode [ecb|cbc]? ?-dir [encrypt|decrypt]? -key keydata ?-iv vector? ?-out channel? ?-chunksize size? ?-pad padchar? [ -in channel | ?--? data ] Perform the blowfish algorithm on either the data provided by the argument or on the data read from the -in channel. If an -out channel is given then the result will be written to this channel. The -key option must be given. This parameter takes a binary string of variable length and is used to generate the blowfish key schedule. You should be aware that creating a key schedule is quite an expensive operation in blowfish so it is worth reusing the key where possible. See Reset. The -mode and -dir options are optional and default to cbc mode and encrypt respectively. The initialization vector -iv takes an 8 byte binary argument which defaults to 8 zeros. See MODES OF OPERATION for more about available modes and their uses. Blowfish is a 64-bit block cipher. This means that the data must be provided in units that are a multiple of 8 bytes. The blowfish command will by default add nul characters to pad the input data to a multiple of 8 bytes if necessary. The programming api commands will never add padding and instead will raise an error if the input is not a multiple of the block size. The -pad option can be used to change the padding character or to disable padding if the empty string is provided as the argument. PROGRAMMING INTERFACE
::blowfish::Init mode keydata iv Construct a new blowfish key schedule using the specified key data and the given initialization vector. The initialization vector is not used with ECB mode but is important for CBC mode. See MODES OF OPERATION for details about cipher modes. ::blowfish::Encrypt Key data Use a prepared key acquired by calling Init to encrypt the provided data. The data argument should be a binary array that is a mul- tiple of the block size of 8 bytes. The result is a binary array the same size as the input of encrypted data. ::blowfish::Decrypt Key data Decipher data using the key. Note that the same key may be used to encrypt and decrypt data provided that the initialization vector is reset appropriately for CBC mode. ::blowfish::Reset Key iv Reset the initialization vector. This permits the programmer to re-use a key and avoid the cost of re-generating the key schedule where the same key data is being used multiple times. ::blowfish::Final Key This should be called to clean up resources associated with Key. Once this function has been called the key may not be used again. MODES OF OPERATION
Electronic Code Book (ECB) ECB is the basic mode of all block ciphers. Each block is encrypted independently and so identical plain text will produce identical output when encrypted with the same key. Any encryption errors will only affect a single block however this is vulnerable to known plaintext attacks. Cipher Block Chaining (CBC) CBC mode uses the output of the last block encryption to affect the current block. An initialization vector of the same size as the cipher block size is used to handle the first block. The initialization vector should be chosen randomly and transmitted as the first block of the output. Errors in encryption affect the current block and the next block after which the cipher will correct itself. CBC is the most commonly used mode in software encryption. EXAMPLES
% blowfish::blowfish -hex -mode ecb -dir encrypt -key secret01 "hello, world!" d0d8f27e7a374b9e2dbd9938dd04195a set Key [blowfish::Init cbc $eight_bytes_key_data $eight_byte_iv] append ciphertext [blowfish::Encrypt $Key $plaintext] append ciphertext [blowfish::Encrypt $Key $additional_plaintext] blowfish::Final $Key REFERENCES
[1] Schneier, B. "Applied Cryptography, 2nd edition", 1996, ISBN 0-471-11709-9, pub. John Wiley & Sons. AUTHORS
Frank Pilhofer, Pat Thoyts BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category blowfish of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. SEE ALSO
3des, des, rc4 KEYWORDS
block cipher, blowfish, cryptography, encryption, security COPYRIGHT
Copyright (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net> blowfish 1.0.3 blowfish(n)
All times are GMT -4. The time now is 09:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy