Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-31-2011, 11:18 PM
|
#1
|
|
LQ Newbie
Registered: Sep 2007
Posts: 2
Rep:
|
Can I execute a shell command and put the result in command field?
Sometimes I have long directory path to type in command field of linux shell, it is very easily mistyped.
Such as :
can I execute "pwd" in command line and make the "pwd" result shown in the command line area and let me modify the command line area to execute another command.
|
|
|
|
07-31-2011, 11:35 PM
|
#2
|
|
Senior Member
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131
Rep:
|
If the issue is having to type it often to get cd there I would make an alias in your home directory:
Code:
ln -s /long/path/to/some/where/good/
Now you have a nice symlink you can easily access by Alternatively you can name it something else:
Code:
ln -s /long/path/to/some/where/good/ fun
now you can cd fun/ hope this helps.
|
|
|
1 members found this post helpful.
|
08-01-2011, 12:39 AM
|
#3
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,987
|
@micxz: your first example is missing the link name
@fran4tw: http://linux.die.net/man/1/ln
Last edited by chrism01; 08-01-2011 at 12:40 AM.
|
|
|
1 members found this post helpful.
|
08-01-2011, 02:31 AM
|
#4
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
I'm not sure what you are asking so this might not be relevant but ...
Code:
dir=$( pwd )
<now do whatever you want with $dir>
|
|
|
|
08-01-2011, 03:39 AM
|
#5
|
|
Senior Member
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131
Rep:
|
Quote:
Originally Posted by chrism01
|
I know. Try it out. Check the "2nd form" in the man page you posted.
|
|
|
|
08-01-2011, 03:44 AM
|
#6
|
|
Senior Member
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131
Rep:
|
Last edited by micxz; 08-01-2011 at 03:45 AM.
|
|
|
1 members found this post helpful.
|
08-01-2011, 04:18 AM
|
#7
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
Quote:
Originally Posted by micxz
|
Thanks micxz -- that's a lot better solution! 
|
|
|
|
08-01-2011, 06:30 AM
|
#8
|
|
Guru
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131
Rep: 
|
Quote:
Originally Posted by micxz
|
Those variables are often forgotten in daily use
Using the output of a program directly might be handy in other tasks than changing working directory, so in that sense I'd still vote for that approach. In addition it should guarantee that you get what you want to, even if the unthinkable happened and somehow $PWD got overwritten just before you typed the command (not probable, but possible).
There are other ways of using the output, or rather "other notations," than the $(command) one. For example in Bash one can also use backticks,
which may or may not be faster to type, depending on your keyboard and fingers. Check the manual of your shell if you're using something different than Bash (if that does not work).
|
|
|
1 members found this post helpful.
|
08-01-2011, 08:40 AM
|
#9
|
|
Moderator
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 10,343
|
Hi,
Along with other suggestion if you have the need to repeat entries then why not setup a .bashrc & .bash_profile for your user with aliases;
Code:
sample .bash_profile;
~$ cat .bash_profile
# .bash_profile
#08-30-06 12:21
#
# Source .bashrc
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
Code:
sample .bashrc;
:~$ cat .bashrc
#.bashrc
#08-30-06 12:20
# Add bin to path
export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"
#export PATH="$PATH:$HOME/bin"
# Dynamic resizing
shopt -s checkwinsize
# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
#08-29-06 11:40
if [ `id -un` = root ]; then
PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
else
PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi
#
# Add color
eval `dircolors -b`
# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'
#08-29-06 11:50
#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
trap "rm -f ~$LOGNAME/.bash_history" 0
#The older KSH-style form
# trap 0 rm -f ~$LOGNAME/.bash_history
The .bashrc is very useful!
Do not forget about 'history';
Quote:
excerpt 'man history';
NAME
history - GNU History Library
COPYRIGHT
The GNU History Library is Copyright (C) 1989-2002 by the Free Software Foundation,
Inc.
DESCRIPTION
Many programs read input from the user a line at a time. The GNU History library
is able to keep track of those lines, associate arbitrary data with each line, and
utilize information from previous lines in composing new ones.
HISTORY EXPANSION
The history library supports a history expansion feature that is identical to the
history expansion in bash. This section describes what syntax features are avail-
able.
History expansions introduce words from the history list into the input stream,
making it easy to repeat commands, insert the arguments to a previous command into
the current input line, or fix errors in previous commands quickly.
History expansion is usually performed immediately after a complete line is read.
It takes place in two parts. The first is to determine which line from the history
list to use during substitution. The second is to select portions of that line for
inclusion into the current one. The line selected from the history is the event,
and the portions of that line that are acted upon are words. Various modifiers are
available to manipulate the selected words. The line is broken into words in the
same fashion as bash does when reading input, so that several words that would oth-
erwise be separated are considered one word when surrounded by quotes (see the
description of history_tokenize() below). History expansions are introduced by the
appearance of the history expansion character, which is ! by default. Only back-
slash (\) and single quotes can quote the history expansion character.
Event Designators
An event designator is a reference to a command line entry in the history list.
! Start a history substitution, except when followed by a blank, newline, = or
(.
!n Refer to command line n.
!-n Refer to the current command line minus n.
!! Refer to the previous command. This is a synonym for `!-1'.
!string
Refer to the most recent command starting with string.
!?string[?]
Refer to the most recent command containing string. The trailing ? may be
omitted if string is followed immediately by a newline.
^string1^string2^
Quick substitution. Repeat the last command, replacing string1 with
string2. Equivalent to ``!!:s/string1/string2/'' (see Modifiers below).
!# The entire command line typed so far.
|
Just a few links to aid you to gaining some understanding;
1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Utimate Linux Newbie Guide
The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
|
|
|
1 members found this post helpful.
|
08-08-2011, 08:27 PM
|
#10
|
|
LQ Newbie
Registered: Sep 2007
Posts: 2
Original Poster
Rep:
|
Thanks to everyone. It really helps. But I am currently working as one man MIS, do'nt have enough time to test all these good suggestion shortly. All the suggestion will test and make the best use of them.
Best regards
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:19 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|