Changing a variable Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing a variable Question
# 1  
Old 02-12-2009
Changing a variable Question

I have a variable:

$FILENAME = /XXXX/XXXX/XXXX/file.dat

I want to set another variable that will give me this:

$FILENAME2=filea.dat

So basically i'm chopping up variable $FILENAME.

Not sure cut will do this as i'm looking at different directories so the characther length may be different e.g.

$FILENAME = /server1/test/data/file.dat
or
$FILENAME = /server17/dept_area/test/data/file.dat


What are the best way's to do this?

Last edited by Pablo_beezo; 02-12-2009 at 10:51 AM..
# 2  
Old 02-12-2009
man basename
Code:
basename $FILENAME
file.dat

# 3  
Old 02-12-2009
Learn more about it with
Code:
man basename

and
Code:
man dirname

, plus learn to use ksh built-ins such as:

Code:
#  Make a name for yourself... 
   typeset -l my_name=${0##*/} 
   typeset    my_path=${0%/*}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dynamically changing environment variable

Linux Redhat, BASH Shell. I want to put this in my .bash_profile I have log files that go to directory paths based in part on other variables such as went DB Name is set in memory. So if the DB Name changes the path to the log file changes. How do I create an environment variable I put into... (6 Replies)
Discussion started by: guessingo
6 Replies

2. UNIX for Dummies Questions & Answers

Changing Path Variable

Blank Blank Blank (11 Replies)
Discussion started by: pvibien
11 Replies

3. UNIX for Dummies Questions & Answers

Getting input and changing variable?

Hi I am new to scripting and have a function in my .sh script file that outputs a html radio button form weather_forecast_config() { echo "" echo "<html><head><title>Welcome</title></head>" echo "<body>" echo "<h2>Weather Forecast - Change City</h2>" echo "<form name="input"... (5 Replies)
Discussion started by: scriptnewbie
5 Replies

4. Shell Programming and Scripting

Changing a global variable to agrv

Hi Guys, I am dealing with some perl scripts written by someone else. There are alot of global variables set at the top of the scripts, which needs to be edited for different users who run the scripts. I am tring to change them so these variables can be set as arguments when running it from the... (1 Reply)
Discussion started by: da2013
1 Replies

5. Shell Programming and Scripting

Changing the variable using awk?

Dear all, I have kind of used both the awk/sed command and found them really useful. But at the necessity I am having right now, I need help. Actually, I would like to do the following in file script.sh PATH535="/eos/uscms/store/user/pooja04//analysis2012/535/mc/summer12/002/tt/" ... (2 Replies)
Discussion started by: emily
2 Replies

6. Shell Programming and Scripting

Changing variable name in for loop

Hi All please help if possible. I am a Unix novice. I have a similar question to the one posted by yonderboy at about a year ago. However his solution does not work for me. The pseudo code for my problem is as follows: for fund in 1 2 3 4 if (FTP is successfully) then FILE_SENT_fund... (2 Replies)
Discussion started by: Seether
2 Replies

7. Homework & Coursework Questions

Unix Script - Changing Variable Question

This is a problem with basic Unix scripting. Thanks for looking! 1. The problem statement, all variables and given/known data: Make a script that will compare 2 given directories and output those filenames that are in Directory 1 and not 2 2. Relevant commands, code, scripts, algorithms:... (1 Reply)
Discussion started by: iamhungry
1 Replies

8. AIX

rerun .profile after changing variable

I changed a $variable in my .profile (AIX unix). I know I could exit out and logon onto unix again, but how do I rerun the .profile at the command line? (2 Replies)
Discussion started by: sboxtops
2 Replies

9. Shell Programming and Scripting

IFS changing the variable value

Hi, I have a while read loop that reads files in a directory and process. The files have spaces in between, so I have the IFS=\n to to read the whole line as one file name. The read works fine but I have a problem with another variable that I set in the beginning of the script. The variable... (1 Reply)
Discussion started by: pvar
1 Replies

10. UNIX for Dummies Questions & Answers

Very simple question about changing PS1 variable at startup!

Hello there ! I am new in this Unix world and just start learning Unix. I have very simple question about changing PS1 variable (Shell Prompt) i have local.profile file in my working directory, i open in vi edit mode and add this line PS1="Hello:>" and i save that file. I disconnected from... (2 Replies)
Discussion started by: abidmalik
2 Replies
Login or Register to Ask a Question