Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I use the shell alot for various tasks, and I was wondering if it is possible to set Bash (in an Xterm) to jump to a particular directory in the file system, e.g ~/home/user/documents? instead of the default (~/) users home dir.
How do you usually launch xterm? Here are a couple of suggestions: from the command line you can launch a new xterm with /home/user/documents as working directory by issuing
moreover you can put this code in a shell function and have a shortcut command at hand.
If using the KDE menu you can try to edit the properties of the xterm launcher. In KDE 3.5 I have a text box called "Work path". I can choose any valid path and every time I start a new xterm, it will open in the specified directory instead of home.
Is it possible to list the directory with an ls alias?
I'm afraid not. The -e option of xterm accepts only commands with their full path or under the directories in $PATH. Aliases and functions aren't valid. Anyway you can still explicitly use aliases in the newly open terminal.
I'm afraid not. The -e option of xterm accepts only commands with their full path or under the directories in $PATH. Aliases and functions aren't valid. Anyway you can still explicitly use aliases in the newly open terminal.
Your aliases are probably being source'd only in
a login shell. The -e option doesn't act like
a login shell. But you can easily construct a
short script that does what you want. Call that
cd+ls, something like (untested...):
#!/bin/bash
# read your aliases (perhaps not the right file)
source ~/.bash_profile
# cd to the first parameter
if test $# != 0
then
cd "$1"
shift 1
fi
# run the rest of the parameters as a command
exec "$@"
So you could use something like this
(given a script named "cd+ls" in your $PATH):
Your aliases are probably being source'd only in
a login shell. The -e option doesn't act like
a login shell. But you can easily construct a
short script that does what you want. Call that
cd+ls, something like (untested...):
#!/bin/bash
# read your aliases (perhaps not the right file)
source ~/.bash_profile
# cd to the first parameter
if test $# != 0
then
cd "$1"
shift 1
fi
# run the rest of the parameters as a command
exec "$@"
So you could use something like this
(given a script named "cd+ls" in your $PATH):
xterm -hold -e cd+ls /bin ls -l
Dickey,
My aliases are in .bashrc, and my .bash_profile sources it.
I am fairly new to scripting, although I understand some basics, but could you explain the parts of your script, I dont understand.
It's all found in "man bash", which is rather long
(even longer than xterm's manpage). However
#!/bin/bash
tells the operating system where to find the shell.
From here on, it's read by bash.
# read your aliases (perhaps not the right file)
source ~/.bash_profile
tells bash to read/interpret the given file.
# cd to the first parameter
if test $# != 0
ask if there's a command-line parameter to this script
then
cd "$1"
change working directory to the given parameter (quoting in case
there are blanks).
shift 1
discard the first parameter.
fi
# run the rest of the parameters as a command
exec "$@"
transfer control to whatever command
is given in the remaining parameters.
(If there are no parameters, not much
will happen).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.