how to store the first content of the folder in a variable?(Urgent)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to store the first content of the folder in a variable?(Urgent)
# 1  
Old 04-08-2008
how to store the first content of the folder in a variable?(Urgent)

Hi All,

I need urgent help. Because just now i have to give this code to my client.

I have a folder name is Testing. this Testing folder contains the following 3 files.

1.txt
2.txt
2.txt

Now I want to store the first value of my folder in a variable say suppose $a.
Means i want that $a=1.txt (It will take from the folder Testing)

Can anybody please tell me the scripting to how to do it???

Please let me know ASAP.
# 2  
Old 04-08-2008
a=`ls -1 | head -1`
# 3  
Old 04-08-2008
Drop the -l from ls -l -- only the file name was requested.
# 4  
Old 04-08-2008
it's not an "l" it is a "1" Smilie but you are right, it works without the "-1" also...
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want to read the content of a specific folder

Why does not work a cd in a shell schript file. How do you get to run it? I use these code: #!/bin/sh cd workspace array=($(ls -d */)) echo ${array} But it doesn't change to workspace editby bakunin: please user CODE-tags as required by the rules. Thank you. (12 Replies)
Discussion started by: Linuxmann
12 Replies

2. Shell Programming and Scripting

Script to store the csv files into a particular folder

I want to write a unix shellScript should store the csv files. into a paticular folder (2 Replies)
Discussion started by: RaghavendraT
2 Replies

3. Shell Programming and Scripting

Delete all content in folder and not show any stderr/stdout

Hi i am a newbie, and have trying something that looked easy at first sight. in this script i want to delete all the files and directories in subdirectory1 (but not delete subdirectory1) and dont show any stderr or stdout messages: i try this but the stderr and stdout is shown...and it says... (2 Replies)
Discussion started by: bash100
2 Replies

4. Shell Programming and Scripting

Store content from array to Spread_sheet using perl

How to store the content from array to either "row-column" or "column-row" order? (0 Replies)
Discussion started by: kavi.mogu
0 Replies

5. 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

6. Shell Programming and Scripting

how to spilit a row into fields and store the field content to the array

consider this is a line A#B#C#D#E#F#G#H note the delimeter is # i want to cut or spilt in to fields using the delimeter # and to store in an array. like this array=A array=B array=C array=D array=E and the array content should be displayed. echo "${array}" echo "${array}"... (5 Replies)
Discussion started by: barani75
5 Replies

7. Shell Programming and Scripting

{Urgent very need help} script for conn oracle and get the content

hi experts, very need help about script how to login into oracle database and select a table and append the query into a file. i have oracle database and have a table named omc_ip with fields like host_id(varchar2(20)),ip(varchar2(10)) and update_date(date). i want to build a script that... (15 Replies)
Discussion started by: bucci
15 Replies
Login or Register to Ask a Question