How to get all the files inside a folder then put the value in a variable?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get all the files inside a folder then put the value in a variable?
# 1  
Old 04-21-2015
How to get all the files inside a folder then put the value in a variable?

Hi

here is my code

Code:
for i in `ls *.cmd`
do
	msg
	aaa imp -U$AAAUSER -P$AAAUSERPWD <$i>>$curdir/import_tap.out -Jutf8
done

I can only get all files with .cmd extension. what i need to get are all the files inside the specific folder

Thanks
# 2  
Old 04-21-2015
If you really mean all files, try:
Code:
for i in .* *
do
	[ -e "$i" ] || continue
	msg
	aaa imp -U$AAAUSER -P$AAAUSERPWD <$i>>$curdir/import_tap.out -Jutf8
done

If you don't want "." files, drop the .* in the for loop. If you only want regular files (instead of files of any type), change the test from -e to -f.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 04-22-2015
many thanks to sir don cragun
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. UNIX for Dummies Questions & Answers

Moving files to a folder with a variable name

hello there- first post here- maybe someone can help- Basically I am trying to copy the contents of a folder to a different folder that has a variable name. the content I want to copy would be in a folder on my desktop called: myfolder the variable folder would look something like: ... (3 Replies)
Discussion started by: infothelonghaul
3 Replies

3. Shell Programming and Scripting

Renumber position 88-94 inside all files matching criteria inside folder

There are 4 files inside one folder matching criteria i.e. File name = ABCJmdmfbsjopXXXXXXX_mm-dd-yyyy_XXX.data Here is the Code which find the files matching criteria:- TS=`date +"%m-%d-%Y"`| for fname in `find . -name "ABCJmdmfbsjop???????_${TS}*.data"` do # Matching File Processing Code.... (1 Reply)
Discussion started by: lancesunny
1 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Touch 10% of the total files inside a folder

I'm trying to make this code below to work but I can't find the way to do the following: I want to make the script to touch only 10% of the total amount of files counted inside the given directory instead of all like it is now. I would greatly appreciate it if someone can give me a direction on... (9 Replies)
Discussion started by: regraphix
9 Replies

5. Shell Programming and Scripting

How i can put the result of a command inside a bash variable?

#!/bin/bash #... for i in `ls -c1 /usr/share/applications` do name="cat $i | grep ^Name= | cut -d = -f2" echo $name #... done Now inside name as output is present: while i want only the result of the command. Ideally i would like obtain that information using only bash ... or... (8 Replies)
Discussion started by: alexscript
8 Replies

6. UNIX for Advanced & Expert Users

how to put a .gz file in already existing archive folder

Hi.. I have a folder within which I have two files : abc.gz and xyz.tar.gz Actualy abc was a 8 GB File and while zipping other files in xyz.tar.gz it could not be zipped due to its large size.. I have zipped abc using -E option of tar. Can someone help to put abc.gz in xyz.tar.gz..... (1 Reply)
Discussion started by: kanus
1 Replies

7. Shell Programming and Scripting

Security for applets files inside a folder

Friends I have a directory structure /a/b/c/applets/ This directory has .java, .class and other applet files. I gave the applets folder 755 permission because these applets are displayed at different web pages of a portal. Now I want to restrict the visibility of all the files in this... (0 Replies)
Discussion started by: dahlia84
0 Replies

8. Shell Programming and Scripting

How to put scp in background inside expect

Gents, I have a wrapper script passing couple of information to an expect script mainly responsible for spawning scp and providing the password (which is transmitted down from the main script). the main script prepare the transfer to couple of servers, idea being to transfer the files in... (3 Replies)
Discussion started by: luc3004
3 Replies

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

10. UNIX for Dummies Questions & Answers

Pattern searching inside Variable - not looking at files

Hi, I've searched this site and not found this already, so if I missed on my search, sorry. I need to pass in a variable to a script, where the first three characters of that variable represent a calendar quarter, and the last 2 characters are the year. I.E. Q0105 for Q1, Q0205 for Q2, and... (3 Replies)
Discussion started by: Rediranch
3 Replies
Login or Register to Ask a Question