LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2007, 12:12 PM   #1
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Rep: Reputation: 30
Grabbing the current directory in shell script


I'm trying to write a script to automatically package my kernel just the way Slackware like it. It would be nice though if I could get the current working directory someone. Is there a way I can do this? The code explains it all
Code:
mkdir $dest/build
mkdir $dest/build/boot
make -C $dest/$source \
  INSTALL_MOD_PATH=$dest/build \
  INSTALL_PATH=$dest/build/boot \
  install
cp $dest/$source/.config $dest/build/boot/config-$version
mv $dest/build/boot/vmlinuz $dest/build/boot/kernel-$version
cd $dest/build/boot
ln -s kernel-$version vmlinuz
ln -s config-$version config
cd -
cd $dest/build
makepkg -l y -c n kernel-$version-i686-1bob.tgz
mv kernel-$version-i686-1bob.tgz ..
cd -
rm -r $dest/build
Note how at on point I have cd - and then cd $dest/build just so I don't lose track of home base.
 
Old 11-02-2007, 12:19 PM   #2
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
Code:
pwd
That Prints Working Directory
 
Old 11-02-2007, 12:24 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Or simply
Code:
echo $PWD
since the variable PWD is updated every time you change dir.
 
Old 11-02-2007, 12:37 PM   #4
stocky021
LQ Newbie
 
Registered: Feb 2006
Distribution: Suse 10
Posts: 20

Rep: Reputation: 0
if you want to save pwd to a variable, use this
variable_name=`pwd`
the ` is next to the 1 key, it is not '
that way you can just user cd "$variable_name" to jump back to that directory...i think
 
Old 11-02-2007, 06:03 PM   #5
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Original Poster
Rep: Reputation: 30
Thanks guys, much appreciated
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My script to burning the current directory to a CD pwc101 LinuxQuestions.org Member Success Stories 6 08-29-2007 12:24 PM
shell script - process directory keith2045 Programming 7 05-31-2007 07:26 PM
cd keeps snapping back to current directory when called from bash script ghrellin Linux - General 5 08-28-2005 12:50 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration