Sponsored Content
Top Forums Shell Programming and Scripting How to assign a variable to an array Post 302451001 by frans on Sunday 5th of September 2010 07:06:18 AM
Old 09-05-2010
Maybe it's better - and sure it's easier - to check files before :
Code:
#!/bin/bash
i=0
while true   # read user input and check files
do
   read -p "enter file name (blank if finished) : " F
   [ -z "$F" ] && break
   [ -f "$F" ] || { echo "File does not exist" && continue; }
   FILE[$i]=$F
   ((i++))
done
for ((i=0; i<${#FILE[@]}; i++))   # print files
do
   echo -e "File number $i\t: ${FILE[$i]}"
done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can I assign the contents of file into an array?

I am trying to assign the contents of file e.g ls "$HOME" into an array. If it is possible then please guide me without using the concept of awk,sed, and perl16 Thanks (10 Replies)
Discussion started by: murtaza
10 Replies

2. Shell Programming and Scripting

Assign dscl output to variable as an array

Greetings folks, I am trying to assign the output of a dscl command (contains name<spaces>id) to a variable as an array. Currently I am piping the output into a tmp file, then reading the tmp file into an array, then parsing the array. I would like to bypass creating the tmp file portion of... (6 Replies)
Discussion started by: macnetdaemon
6 Replies

3. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

4. Shell Programming and Scripting

assign value to array variable

Hi, I have a piece of code as follows: i=0 while read LINE do var = "$LINE" i=$((i+1)) echo "${var}" done < file I want to assign value to the array var. However, when i execute the script i get a error. Please can you help me know what i am missing. I ultimately want to... (2 Replies)
Discussion started by: sunrexstar
2 Replies

5. Shell Programming and Scripting

How to assign an array element to a variable

Hi every one.. I'm new to shell scripting... I would like to assign a single array element to a variable... Is it possible to do it.... Could any body help me.... (3 Replies)
Discussion started by: kaushik_87
3 Replies

6. Shell Programming and Scripting

Assign value to array separated by #

Hi all , I have a string like para1#para2#para3 i want to assign para1 as first element para2 as second and so on i tried IFS=# set -A array para1#para2#para3 echo ${array} para1 para2 para3 i want echo ${array} para1 (2 Replies)
Discussion started by: max_hammer
2 Replies

7. Shell Programming and Scripting

how to assign file names to array variable?

I wish to assign file names with particular extention to array variables. For example if there are 5 files with .dat extention in /home/sam then i have to assign these 5 files to an array. plz help me how to accomplish this. Thanks in advance. (4 Replies)
Discussion started by: siteregsam
4 Replies

8. Shell Programming and Scripting

How can we assign value to an array variable from an external file?

is it possible to assign value to an array variable from an external file?? if yes then how?? I am using below code but its not working. #!bin/bash myarray < file_name echo ${mayarray} (6 Replies)
Discussion started by: mukulverma2408
6 Replies

9. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

10. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies
SHASUM(1)						 Perl Programmers Reference Guide						 SHASUM(1)

NAME
shasum - Print or Check SHA Checksums SYNOPSIS
Usage: shasum [OPTION] [FILE]... or: shasum [OPTION] --check [FILE] Print or check SHA checksums. With no FILE, or when FILE is -, read standard input. -a, --algorithm 1 (default), 224, 256, 384, 512 -b, --binary read files in binary mode (default on DOS/Windows) -c, --check check SHA sums against given list -p, --portable read files in portable mode produces same digest on Windows/Unix/Mac -t, --text read files in text mode (default) The following two options are useful only when verifying checksums: -s, --status don't output anything, status code shows success -w, --warn warn about improperly formatted SHA checksum lines -h, --help display this help and exit -v, --version output version information and exit The sums are computed as described in FIPS PUB 180-2. When checking, the input should be a former output of this program. The default mode is to print a line with checksum, a character indicating type (`*' for binary, `?' for portable, ` ' for text), and name for each FILE. DESCRIPTION
The shasum script provides the easiest and most convenient way to compute SHA message digests. Rather than writing a program, the user simply feeds data to the script via the command line, and waits for the results to be printed on standard output. Data can be fed to shasum through files, standard input, or both. The following command shows how easy it is to compute digests for typical inputs such as the NIST test vector "abc": perl -e "print qw(abc)" | shasum Or, if you want to use SHA-256 instead of the default SHA-1, simply say: perl -e "print qw(abc)" | shasum -a 256 Since shasum uses the same interface employed by the familiar sha1sum program (and its somewhat outmoded anscestor md5sum), you can install this script as a convenient drop-in replacement. AUTHOR
Copyright (c) 2003-2008 Mark Shelor <mshelor@cpan.org>. SEE ALSO
shasum is implemented using the Perl module Digest::SHA or Digest::SHA::PurePerl. perl v5.12.4 2013-03-18 SHASUM(1)
All times are GMT -4. The time now is 05:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy