0

I'm writing my first script that takes a file and moves it to another folder, except that I want to change the filename of the file to filename_inode instead of just filename incase there are any files with the same name

I've figured out how to show this by creating the following 4 variables

inode=$(ls -i $1 | cut -c1-7) #lists the file the user types, cuts the inode from it

space="_" #used to put inbetween the filename and bname

bname=$(basename $1) #gets the basename of the file without the directory etc

bnamespaceinode=$bname$space$inode #combines the 3 values into one variable

echo "$bnamespaceinode #prints filename_inode to the window

So the bottom echo shows filename_inode which is what I want, except now when I try to move this using mv or cp i'm getting the following errors

enter image description here enter image description here

I dont think it's anything wrong with the syntax i'm using for the mv and cv commands, and so I'm thinking I need to concatenate the 3 variables into a new file or use the result of the first and then append the other 2 to that file?

I've tried both of the above but still not having any luck, any ideas?

Thanks

user2058186
  • 287
  • 2
  • 13
  • It would be easier if you just gave an example showing what you have, and what you expect. Include the source and target directories also please. – Rein Oct 15 '14 at 20:44

1 Answers1

1

Without clearer examples, I guess this could work:

$TARGETDIR=/my/target/directory
mv $1 $TARGETDIR/$(basename "$1" | sed 's/_.*/_inode/')
Rein
  • 477
  • 2
  • 7