Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Cut from inside a saved variable Post 302336458 by strasner on Wednesday 22nd of July 2009 07:50:02 AM
Old 07-22-2009
Cut from inside a saved variable

ok, heres my problem.

i have saved the last line from a ls -l command into a variable. What i want to do is be able to cut the second character into that (i.e. the r if its there of the - if its not there) and save that value into another variable.

here is the current code i have to save the ls -l into a variable:

Code:
var1=$(ls -1 $1 | tail -1)

and here is what code i have come up with to get the second character from that line:

Code:
cut -c 2 $var1

please help me, been stuck on this problem for about an hour now.

(also, i cant use SED or AWK so bash soloutions would be awesome)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies

2. Shell Programming and Scripting

How to replace variable inside the variable

hi sir, i need your help for this script inside /rnmucdr/ednms05/ken/xMNBDF045_Script.sql content variable like this select * from invoice where bill_date=$BILLDATE and startNum=$STARTPARTNNUM and total_partn=$TOTALPARTN if i just paste this replace with the $SCRIPT it works great,if... (31 Replies)
Discussion started by: mani_um
31 Replies

3. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies

4. Shell Programming and Scripting

passing a variable inside another variable.

Any help would be great. I know this is a dumb way of doing this, but I would like to know if there is a solution doing it this way. I'm very new at this and I'd like to learn more. Thanks! :D:D count=0 while ; do echo "enter your name" read name_$count let count=count+1 done ... (2 Replies)
Discussion started by: reconflux
2 Replies

5. Shell Programming and Scripting

Can STDERR be saved to a variable

Guys i'm trying to save STDERR to a variable for a portion of my ksh script on solaris. I know i can create redirects to files as such: exec 4>/tmp/lava print "This will be saved to /tmp/lava and not screen"; >&4 print "This will be seen on screen" >&2 I want to save the STDOUT of a... (4 Replies)
Discussion started by: lavascript
4 Replies

6. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

7. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

8. Shell Programming and Scripting

evaluating a variable inside a variable

Hi there, i think im getting myself a little confused and need some help :wall: I am reading in a bunch of variables to my script from an external file and need to validate that a value has been set for each so if you can imagine, the user is required to pass in 4 values... (3 Replies)
Discussion started by: rethink
3 Replies

9. Shell Programming and Scripting

To print value for a $variable inside a $variable or file

Hi guys, I have a file "abc.dat" in below format: FILE_PATH||||$F_PATH TABLE_LIST||||a|b|c SYST_NM||||${SRC_SYST} Now I am trying to read the above file and want to print the value for above dollar variables F_PATH and SRC_SYST. The problem is it's reading the dollar variables as... (5 Replies)
Discussion started by: abcabc1103
5 Replies

10. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies
MYSQLI_STMT.BIND_PARAM(3)						 1						 MYSQLI_STMT.BIND_PARAM(3)

mysqli_stmt::bind_param - Binds variables to a prepared statement as parameters

       Object oriented style

SYNOPSIS
bool mysqli_stmt::bind_param (string $types, mixed &$var1, [mixed &$...]) DESCRIPTION
Procedural style bool mysqli_stmt_bind_param (mysqli_stmt $stmt, string $types, mixed &$var1, [mixed &$...]) Bind variables for the parameter markers in the SQL statement that was passed to mysqli_prepare(3). Note If data size of a variable exceeds max. allowed packet size (max_allowed_packet), you have to specify b in $types and use mysqli_stmt_send_long_data(3) to send the data in packets. Note Care must be taken when using mysqli_stmt_bind_param(3) in conjunction with call_user_func_array(3). Note that mysqli_stmt_bind_param(3) requires parameters to be passed by reference, whereas call_user_func_array(3) can accept as a parameter a list of variables that can represent references or values. PARAMETERS
o $ stmt -Procedural style only: A statement identifier returned by mysqli_stmt_init(3). o $types - A string that contains one or more characters which specify the types for the corresponding bind variables: Type specification chars +----------+---------------------------------------------------+ |Character | | | | | | | Description | | | | +----------+---------------------------------------------------+ | i | | | | | | | corresponding variable has type integer | | | | | d | | | | | | | corresponding variable has type double | | | | | s | | | | | | | corresponding variable has type string | | | | | b | | | | | | | corresponding variable is a blob and will be sent | | | in packets | | | | +----------+---------------------------------------------------+ o $var1 - The number of variables and length of string $types must match the parameters in the statement. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Object oriented style <?php $mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world'); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } $stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)"); $stmt->bind_param('sssd', $code, $language, $official, $percent); $code = 'DEU'; $language = 'Bavarian'; $official = "F"; $percent = 11.2; /* execute prepared statement */ $stmt->execute(); printf("%d Row inserted. ", $stmt->affected_rows); /* close statement and connection */ $stmt->close(); /* Clean up table CountryLanguage */ $mysqli->query("DELETE FROM CountryLanguage WHERE Language='Bavarian'"); printf("%d Row deleted. ", $mysqli->affected_rows); /* close connection */ $mysqli->close(); ?> Example #2 Procedural style <?php $link = mysqli_connect('localhost', 'my_user', 'my_password', 'world'); /* check connection */ if (!$link) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } $stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)"); mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent); $code = 'DEU'; $language = 'Bavarian'; $official = "F"; $percent = 11.2; /* execute prepared statement */ mysqli_stmt_execute($stmt); printf("%d Row inserted. ", mysqli_stmt_affected_rows($stmt)); /* close statement and connection */ mysqli_stmt_close($stmt); /* Clean up table CountryLanguage */ mysqli_query($link, "DELETE FROM CountryLanguage WHERE Language='Bavarian'"); printf("%d Row deleted. ", mysqli_affected_rows($link)); /* close connection */ mysqli_close($link); ?> The above examples will output: 1 Row inserted. 1 Row deleted. SEE ALSO
mysqli_stmt_bind_result(3), mysqli_stmt_execute(3), mysqli_stmt_fetch(3), mysqli_prepare(3), mysqli_stmt_send_long_data(3), mysqli_stmt_errno(3), mysqli_stmt_error(3). PHP Documentation Group MYSQLI_STMT.BIND_PARAM(3)
All times are GMT -4. The time now is 03:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy