Notices


Reply
Thread Tools
Posts: 692 | Thanked: 264 times | Joined on Dec 2009
#1
Check this out, a shellscript to get the absolute path to any file:

Code:
#! /bin/sh

ABPATH=$(readlink -f "$1")
echo $ABPATH
"Big deal" you say? Well this can do some very handy things. For example if you use Easy Debian apps via the debbie or sudo debian commands, you know what a PITA it is to have to specify an absolute path all the time. So let's say you're in /media/mmc1/Documents/PDFs/school/coursexyz/ and want to open doc1.pdf with evince. You just do:

debbie evince `~/getabpath doc1.pdf`

(this example assumes you put the script in ~/ but you could put it in /usr/bin)

You could even integrate it into your debbie/debian scripts in /usr/bin to make this sort of thing automatic.
__________________
"Impossible is not in the Maemo vocabulary" - Caballero

Last edited by GameboyRMH; 2010-05-31 at 16:13.
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#2
Pardon my ignorance, I don't use Easy Debian, but why won't
Code:
debbie evince doc1.pdf
work?
 
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#3
Nice, but ......

1: why do you use the variable? couldn't you just do a "echo $(readlink -f $1)" ?

2: why not call from commandline readlink -f FILE ? Or you could set up an alias called readlinkf as `readlink -f` or even shorten the alias to rlf
 
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#4
Originally Posted by Joorin View Post
Pardon my ignorance, I don't use Easy Debian, but why won't
Code:
debbie evince doc1.pdf
work?
I also don't know exactly how EasyDebian works but I guess all file calls need absolute paths. This happens.
 
Posts: 692 | Thanked: 264 times | Joined on Dec 2009
#5
Originally Posted by Joorin View Post
Pardon my ignorance, I don't use Easy Debian, but why won't
Code:
debbie evince doc1.pdf
work?
Because Easy Debian runs in a chroot, you don't get the same working directory when you use a debbie/sudo debian command, so relative paths are useless.

And x-lette you're totally right, I could have done both of those things. I thought I'd just lay it out in a more self-explanatory manner to help the noobs understand.
__________________
"Impossible is not in the Maemo vocabulary" - Caballero

Last edited by GameboyRMH; 2010-05-31 at 16:08.
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#6
Originally Posted by x-lette View Post
I also don't know exactly how EasyDebian works but I guess all file calls need absolute paths. This happens.
That sounds like a bug in the Easy Debian wrapper script that should be fixed instead of using scripts like the one above.

CWD is known. What more is needed?
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#7
Originally Posted by GameboyRMH View Post
Because Easy Debian runs in a chroot, you don't get the same working directory when you use a debbie/sudo debian command, so relative paths are useless.

And x-lette you're totally right, I could have done both of those things. I thought I'd just lay it out in a more self-explanatory manner to help the noobs understand.
But, your script supplies the full path, from the root, down to your file, so Easy Debian must still be able to handle the whole file system. Or is the script run after the chroot has been set up? Then it's a matter of letting the wrapper script know where you started it from and if the file name starts with a "/". CWD is known when you start the wrapper script.

And, please, this is not me trying to bash () your script or your idea, I'm just trying to understand.
 
Posts: 692 | Thanked: 264 times | Joined on Dec 2009
#8
Originally Posted by Joorin View Post
But, your script supplies the full path, from the root, down to your file, so Easy Debian must still be able to handle the whole file system. Or is the script run after the chroot has been set up? Then it's a matter of letting the wrapper script know where you started it from and if the file name starts with a "/". CWD is known when you start the wrapper script.

And, please, this is not me trying to bash () your script or your idea, I'm just trying to understand.
When you run a command with debbie/sudo debian, it always starts in /home/user. So if you're in /media/mmc1 and you run a "evince doc.pdf," debbie will look for doc.pdf in /home/user and won't work.

Also I looked at the debbie / debian scripts and it isn't possible to make the scripts convert paths unless you assume that a certain argument will always be a path.
__________________
"Impossible is not in the Maemo vocabulary" - Caballero
 
Posts: 4 | Thanked: 2 times | Joined on Apr 2010
#9
If, in /usr/bin/debbie, you replace the line
Code:
 sudo /sbin/debian su $DEBUSER -c "$*"
with
Code:
  sudo /sbin/debian su $DEBUSER -l -c "cd $PWD; $*"
the script knows from where you issued the debbie command. Then you can issue commands like
Code:
  cd /home/user
  debbie ls -l dir/file.txt
and get the appropriate output instead of "No such file".

Note that for this to work the PWD directory must be mounted in /.debian, for example, the directory /home must be mounted as /.debian/home.

Note also that you can issue compound commands with debbie by surrounding the commands with double quotes, for example,
Code:
  cd /home/user
  debbie "ls MyDocs; df .; df /"
 

The Following User Says Thank You to stanman For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 13:49.