Sponsored Content
Full Discussion: variables in a script
Top Forums Shell Programming and Scripting variables in a script Post 29175 by Bab00shka on Tuesday 1st of October 2002 10:04:45 AM
Old 10-01-2002
Question variables in a script

Hi,

I have a variable (var) which can be any number. I would like to use the cut command on a string depending on the variable.

eg
var=4
echo $string | cut -c 1-$var

This doesn't work as cut sees $var as $var rather than as 4. Can anyone suggest how I can evaluate $var in the cut command so cut sees $var as 4 ?

Many thanks
HelenSmilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ? I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if then # error processing fi -----... (10 Replies)
Discussion started by: rajarkumar
10 Replies

2. Shell Programming and Scripting

Script that takes in variables, and outputs to another text or script file

Ok, I sort of need to create a command files that will be ftped to another server to run. I have some input variable that will need to be read, and then transformed into another script file. Here are some examples. Server 1: outputCmd.sh passing in ./outputCmd.sh nh8oaxt Release_4_0... (1 Reply)
Discussion started by: orozcom
1 Replies

3. Shell Programming and Scripting

getting variables from another script

I have 2 scripts.The first script greps something and prints it say a.sh #!/bin/sh ccc="grep something and cut something" echo $ccc When you run this it gives a value say "100" I have b.sh and I have #!/bin/sh status=`/home/a.sh` status_code=$? echo status_code When I run... (7 Replies)
Discussion started by: gubbu
7 Replies

4. Shell Programming and Scripting

Using variables across script

Hi, I want to take input from one script like : 1. Enter ip address : 2. Enter port : Now, I want to - a. Store these in variables, b. Call a separate script (say, x) from this script (say, y) c. And use the stored variables in the called script (i.e. in script 'x'). How do I... (5 Replies)
Discussion started by: angshuman_ag
5 Replies

5. Shell Programming and Scripting

Variables of executed script available in executing script

Hi, I have a script get_DB_var.ksh which do a data base call and get some variables as below: sqlplus -silent $user/$pass@dbname <<END select col1, col2, col3 from table_name where col4=$1; exit; END Now I want to access all these variables i.e.... (9 Replies)
Discussion started by: dips_ag
9 Replies

6. Shell Programming and Scripting

calling script with multiple variables in second script

Hi All, Just give me an idea on how to do the below logic. 1. I have one master script masterload.sh, the usage of this script is a. masterload.sh FULL BFLF_LOAD.txt b. masterload.sh DELTA TDLD_LOAD.txt c.masterload.sh USER MAS_LOAD.txt FULL , DELTA ,USER are the varaibles based... (1 Reply)
Discussion started by: mora
1 Replies

7. Shell Programming and Scripting

Ask variables to user by script

Hi. Is there any way of in a script ask the user something and with the user answer retreave a internal result that uses the variable that the user had introduced? Thanks (3 Replies)
Discussion started by: whity
3 Replies

8. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

9. UNIX for Dummies Questions & Answers

Variables in perl script

Hi Chaps, Im after some advise with a script i've written however doesnt appear to work how I would like. Basically I have a perl script which sucessfully pulls an expect script to login to multiple nodes and obtain some output from the nodes (total number of nat ports that are in use... (0 Replies)
Discussion started by: mutley2202
0 Replies

10. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies
INTVAL(3)								 1								 INTVAL(3)

intval - Get the integer value of a variable

SYNOPSIS
int intval (mixed $var, [int $base = 10]) DESCRIPTION
Returns the integer value of $var, using the specified $base for the conversion (the default is base 10). intval(3) should not be used on objects, as doing so will emit an E_NOTICE level error and return 1. PARAMETERS
o $var - The scalar value being converted to an integer o $base - The base for the conversion Note If $base is 0, the base used is determined by the format of $var: o if string includes a "0x" (or "0X") prefix, the base is taken as 16 (hex); otherwise, o if string starts with "0", the base is taken as 8 (octal); otherwise, o the base is taken as 10 (decimal). RETURN VALUES
The integer value of $var on success, or 0 on failure. Empty arrays return 0, non-empty arrays return 1. The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807. Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply. EXAMPLES
Example #1 intval(3) examples The following examples are based on a 32 bit system. <?php echo intval(42); // 42 echo intval(4.2); // 4 echo intval('42'); // 42 echo intval('+42'); // 42 echo intval('-42'); // -42 echo intval(042); // 34 echo intval('042'); // 42 echo intval(1e10); // 1410065408 echo intval('1e10'); // 1 echo intval(0x1A); // 26 echo intval(42000000); // 42000000 echo intval(420000000000000000000); // 0 echo intval('420000000000000000000'); // 2147483647 echo intval(42, 8); // 42 echo intval('42', 8); // 34 echo intval(array()); // 0 echo intval(array('foo', 'bar')); // 1 ?> NOTES
Note The $base parameter has no effect unless the $var parameter is a string. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | Throws E_NOTICE and returns 1, when an object is | | | passed to $var. | | | | +--------+---------------------------------------------------+ SEE ALSO
boolval(3), floatval(3), strval(3), settype(3), is_numeric(3), Type juggling, BCMath Arbitrary Precision Mathematics Functions. PHP Documentation Group INTVAL(3)
All times are GMT -4. The time now is 09:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy