LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 02-21-2019, 10:45 AM   #1
Terry Coats
Member
 
Registered: Mar 2017
Posts: 122

Rep: Reputation: 54
How do I make pushd and popd work when I use sudo to run as root to install things?


I'm compiling blfs 8.3 and had a problem when trying to install OpenJPEG-2.3.0.
I've configured sudo to let me run as root without a password because it
takes too long to enter a password every time I install something.
I get this problem:
Code:
sudo pushd ../doc &&
  for man in man/man?/* ; do
      install -v -D -m 644 $man /usr/share/$man
  done 
popd
tells me pushd command not found. I know it's not a command but
a bash builtin but I don't know how to make it work. The book does
not say what to do in this case. I've seen this problem in the past
but I've forgotten what I did to make it work. I finally got this
software installed by lots of going back and forth from console
to xterm but it was time-consuming and annoying. I got fluxbox running
and I'm doing installing from two xterm windows from there, copying
and pasting from one xterm running links to another doing the compiling.
Does anyone know the solution to making pushd work in this case?
Oh, and I've already done lots of googling. No solution found.
 
Old 02-21-2019, 11:49 AM   #2
Terry Coats
Member
 
Registered: Mar 2017
Posts: 122

Original Poster
Rep: Reputation: 54
Ok. I've figured out a solution. I've got to fully become root with:
Code:
sudo su
to make the pushd stuff work. I don't know if that's the only way but
it works so I'll stick with it until I find something else.
Typing "exit" afterwards returns me to my regular user. I'll mark this
solved.
 
Old 02-21-2019, 10:21 PM   #3
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050
How do I make pushd and popd work when I use sudo to run as root to install things?

I believe you can also use as your limited user:

Code:
sudo -i <command>
It runs an interactive shell with root privileges.
 
1 members found this post helpful.
Old 02-22-2019, 12:01 AM   #4
Terry Coats
Member
 
Registered: Mar 2017
Posts: 122

Original Poster
Rep: Reputation: 54
Thanks. I think that's what I was looking for.
 
Old 02-22-2019, 02:14 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
sudo su is deprecated.
sudo is completely enough to be root. there is no such thing: "fully become root".
pushd is a shell built-in, and sudo cannot be used that way. sudo is used to execute binary commands, not a bash function, alias or built-ins.
As it was already mentioned sudo -i will run a shell and that shell (bash) will understand (and will be able to execute) functions, aliases and/or built-in commands.
see man sudo for details.
 
Old 02-22-2019, 09:25 AM   #6
Terry Coats
Member
 
Registered: Mar 2017
Posts: 122

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by pan64 View Post
sudo su is deprecated.
sudo is completely enough to be root. there is no such thing: "fully become root".
pushd is a shell built-in, and sudo cannot be used that way. sudo is used to execute binary commands, not a bash function, alias or built-ins.
As it was already mentioned sudo -i will run a shell and that shell (bash) will understand (and will be able to execute) functions, aliases and/or built-in commands.
see man sudo for details.
I don't care if it's deprecated or not as long as it gets me to where I can
copy and paste instructions from the book.
Why are you nitpicking me over the words I used? Yes I realized pushd wouldn't
work that's why I asked for help.
You are not helpful. Why did you even comment except to be a smartass?
 
Old 02-22-2019, 09:36 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Basically I wanted to give you some additional info. Some details, probably to understand better. But you don't care about that. That is ok. You do not have to understand.
 
Old 02-22-2019, 09:57 AM   #8
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050
While sudo works, why not write your script with the goal of running it as root? Sudo isn't meant to be used for everything like many guides recommend and often will not provide you with full root privs to carry out your tasks. Often it is better to simply log directly into your root account (from the log in prompt or with su), do whatever work you need to do, then log out.
 
Old 02-22-2019, 10:20 AM   #9
Terry Coats
Member
 
Registered: Mar 2017
Posts: 122

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by mralk3 View Post
While sudo works, why not write your script with the goal of running it as root? Sudo isn't meant to be used for everything like many guides recommend and often will not provide you with full root privs to carry out your tasks. Often it is better to simply log directly into your root account (from the log in prompt or with su), do whatever work you need to do, then log out.
It's the writers of the BLFS-8.3 book who've written the installation
instructions. I use sudo because it works 99 percent of the time
when copying and pasting these installation instructions as root.
It takes hours to compile this software and any shortcuts to doing it
are a help. The pushd popd thing was an unexpected obstacle to what
had been smooth sailing up to that point.
Thanks again for the "sudo -i" tip.
 
Old 02-22-2019, 11:48 AM   #10
stoat
Member
 
Registered: May 2007
Distribution: LFS
Posts: 628

Rep: Reputation: 185Reputation: 185
Quote:
Originally Posted by Terry Coats

I get this problem:
Code:
sudo pushd ../doc &&
  for man in man/man?/* ; do
      install -v -D -m 644 $man /usr/share/$man
  done 
popd
tells me pushd command not found.
I do that kind of thing this way...
Code:
pushd ../doc
  for man in man/man?/* ; do
      sudo install -v -D -m 644 $man /usr/share/$man
  done 
popd
You don't need to be root to do the pushd and popd; just the install command. And in a script, get rid of the ampersands.


P.S.: I looked at that page in the BLFS book, and it's written that way expecting us to change to the root user in a terminal to do all that stuff being discussed here. But if you instead prefer to use sudo, or if you are writing a build script that will use sudo, then the book's line-by-line steps may not work with sudo exactly as written following anywhere it says "now as the root user:". In this particular case, the pushd, popd, and for-do loop do not need to be run as root. Only the command inside the for-do loop. The book authors are not going to bother writing about that. There probably are other examples of this or similar situations in the book. Some examples where the book intends for us to use sudo and is written in a special way to allow that are the Xorg libraries, applications, and fonts.

Last edited by stoat; 02-22-2019 at 02:07 PM.
 
1 members found this post helpful.
Old 02-22-2019, 12:18 PM   #11
Terry Coats
Member
 
Registered: Mar 2017
Posts: 122

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by stoat View Post
I do that kind of thing this way...
Code:
pushd ../doc
  for man in man/man?/* ; do
      sudo install -v -D -m 644 $man /usr/share/$man
  done 
popd
You don't need to be root to do the pushd and popd; just the install command. And in a script, get rid of the ampersands.
Thanks for this idea. This is what I'm looking for. Ways to make this work.
 
  


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
pushd and popd emulator linuxcoder Programming 5 10-28-2012 04:54 PM
LXer: Use "pushd" and "popd" for quick switching between directories LXer Syndicated Linux News 0 07-13-2012 07:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 02:39 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