HOw to get a variable allocation

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers HOw to get a variable allocation
# 1  
Old 12-17-2007
HOw to get a variable allocation

HI Gurus,

I had a requirement where i want to allocate a file name into a variable and get the file name in the subj of email.

Suppose i have a file File002.pdx in the folder /home/pcs/system/files/File002.pdx

Iam using a variable a = `ls /home/pcs/system/files/*.pdx`

Iam using * because the file name will be changing time to time.

When iam using $a in the sub folder its coming complete path into the subject of email

please help me the sample code
# 2  
Old 12-17-2007
If U have more than 1 file in your directory, U will get a list of files names with full path in your variable.

If U have only 1 file like *.pdx, do this to get the file name with extension:
fnamex=$(basename /home/pcs/system/files/*.pdx)

... the file name without extension
fname=$(basename /home/pcs/system/files/*.pdx .pdx)

But if the command " ls basename /home/pcs/system/files/*.pdx " gives more than one file, U need to do a for loop, like this :

for ff in $(ls home/pcs/system/files/*.pdx .pdx); do
fx=$(basename $ff)
echo $fx

To get the directory name U can use " dirname " instead of " basename "

is this what U asked for ??
# 3  
Old 12-18-2007
Thanks fr ur reply

Actual we have only one file in it.
So the code is working
Thanks fr ur prompt reply
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Memory allocation problem

I am using ubuntu. I have written a program to calculate prime factors. it works perfectly fine till entered number is less than 9989 (or so ) but when one enters a number higher than that, for example 15000, it does not work. Can anyone guide me whats the problem ? although new codes are welcome,... (2 Replies)
Discussion started by: Abhishek_kumar
2 Replies

2. Shell Programming and Scripting

Nested variable allocation

I've made a number of errors with this and am trying to work a solution within the same framework. /bin/ksh for host_name in ahost1 ahost2 bhost1 bhost2 do for host_prefix in a b do if echo ${host_name} | grep -qi ${host_prefix} then if ... (1 Reply)
Discussion started by: squrcles
1 Replies

3. Programming

C++/ROOT Memory Allocation?

Hello, I am new to C++ programming, so I'm still getting a feel for things. I recently wrote a simple C++ program (to be used as a ROOT Macro) to conduct a statistical analysis of a varied version of the Monty Hall problem (code below). Basically, the programs runs a few simple calculations to... (7 Replies)
Discussion started by: Tyler_92
7 Replies

4. Shell Programming and Scripting

memory allocation to a variable

hello all.. i'm a beginner in shell scripting. I need to know what is really happening when we are creating a variable in shell scripting? how memory is allocated for that variable? (3 Replies)
Discussion started by: aarathy
3 Replies

5. Solaris

Block-based allocation and Extent-based allocation in Solaris

Hi guys! Could you tell me what's this figure about? (See the attached figure below.) This is a representation of block allocation filesystem and extent allocation filesystem in Solaris. Does this mean that in a block-based allocation, data are placed in individual blocks while in... (0 Replies)
Discussion started by: arah
0 Replies

6. Programming

Memory allocation in C

Hi Experts I need some help in static memory allocation in C. I have a program in which I declared 2 variables, one char array and one integer. I was little surprised to see the addresses of the variables. First: int x; char a; printf("%u %u\n', &x, a); I got the addresses displayed... (2 Replies)
Discussion started by: unx_freak
2 Replies

7. Programming

dynamic allocation vs static allocation in c

i wrote a tiny version of tail command using a large buffer statically allocated but, in a second time, i found another version in which i use a bidimensional array dynamically allocated. here is the first version /*my tiny tail, it prints the last 5 line of a file */ #include<stdio.h>... (4 Replies)
Discussion started by: lucasclaus
4 Replies

8. AIX

AIX UID allocation

I would like to start my AIX UID allocation at a number far above the standard something like say 1000 however for the life of me i can't seem to find a place where i am able to set or see where aix looks for the user id's by default for allocation common sense would say that it looks in... (1 Reply)
Discussion started by: dgaixsysadm
1 Replies

9. AIX

Device allocation on an LPAR

Has anyone ever encountered the following error message: Unable to allocate the I/O slot ,,,,,,, for activation. This I/O slot is identified as a required adapter to activate this partition. This was sent to me by one of the AIX admins working with me. (1 Reply)
Discussion started by: johnf
1 Replies

10. UNIX for Dummies Questions & Answers

memory allocation

I would like to know how I could allocate some more memory to a process. Please note that I am not the root user. (1 Reply)
Discussion started by: sagar
1 Replies
Login or Register to Ask a Question