Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-04-2012
Registered User
 
Join Date: Jun 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Working with file-names

Hello forum,

I am new to shellscripting.

My first goal is to write a script that verifies that for each file in one path there is an associated one in another path.

The association is deviated by a distinct 'part' of the filename(s). Therefore I wanted to work with substitution.

Here is what I have so far:

Code:
for i in /my/source/path/*
 do
  var=basename $i
  echo ${var//cutme/""}
 done

I expected to put every filename reduced by the string 'cutme' to stdout. But it will tell me it has not sufficient privileges. I think it tries to rename the actual filename, but I just want to work with a 'copy'.

How can I work with filenames without actually changing it?

regards
Sponsored Links
    #2  
Old 06-04-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,341
Thanks: 144
Thanked 1,754 Times in 1,591 Posts
Try:

Code:
var=$(basename $i)

or

Code:
var=${i##*/}

Sponsored Links
    #3  
Old 06-04-2012
Registered User
 
Join Date: Jun 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
It worked.
Thank you Scrutinizer.

So
Code:
var=$(some)

means copy the value to a new variable?
    #4  
Old 06-04-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,341
Thanks: 144
Thanked 1,754 Times in 1,591 Posts
This is called command substitution.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Split File by Pattern with File Names in Source File... Awk? cul8er Shell Programming and Scripting 2 11-25-2011 01:38 PM
How to split a data file into separate files with the file names depending upon a column's value? nithins007 Shell Programming and Scripting 2 09-25-2011 07:38 AM
Searching for file names in a directory while ignoring certain file names 2reperry Shell Programming and Scripting 2 12-13-2009 09:16 PM
Working with folder names ricksj UNIX for Dummies Questions & Answers 6 01-23-2009 11:01 AM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 04:25 AM



All times are GMT -4. The time now is 08:41 AM.