sudo E option does not work?
/etc/sudoers by default has a setting to reset the environment. And also defines a default secure_path which is in effect when you run sudo -E [cmd].
You will need to edit the /etc/sudoers file and add 'env_keep' and mention the variables you want to preserve.
Default env_keep += "PATH"
but before this comment out the secure_path line. Then try your command via sudo -E.
sudo echo something /etc/privilegedFile doesn't work
Use tee --append
or tee -a
.
echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list
Make sure to avoid quotes inside quotes.
To avoid printing data back to the console, redirect the output to /dev/null.
echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list > /dev/null
Remember about the (-a
/--append
) flag!
Just tee
works like >
and will overwrite your file. tee -a
works like >>
and will write at the end of the file.
echo -e option in ubuntu doesn't work
It could depend from the shell you guys are using (echo is often implemented inside the shell)
this is what happens in OS X (Mountain Lion):
$ bash
bash-4.2$ echo -e foo
foo
bash-4.2$ sh
sh-3.2$ echo -e foo
-e foo
The same for OpenSUSE, and Ubuntu.
-e
option is not compliant to POSIX (I'm not sure, but it should be the default behavior), btw, to print formatted text, printf
is more appropriate command.
From the information you provide, it looks to me that your makefile has a bug (portability issue).
On OSX man echo
doesn't list the -e
option too, btw. On Ubuntu 12.10 the -e
is present on my computer, on my router BusyBox v1.13.4 also accepts the -e
(it's internal command for busybox)
But probably it's just the /bin/sh
using internal command and ignoring it.
==== UPDATE:
In your makefile remove the $(TOOLSDIR) in front of echo:
ECHO = echo -e
in fact if you specify the path of the echo (i.e. /bin/echo
) you force the shell to execute the program from the filesystem instead of the one implemented internally by the shell:
$ echo -e foo
foo
$ /bin/echo -e foo
-e foo
Rails: Why sudo command is not recognized?
Sudo is a Unix specific command designed to allow a user to carry out administrative tasks with the appropriate permissions.
Windows does not have (need?) this.
Run the command with the sudo removed from the start.
What does -E mean in sudo apt-get
-E preserves environment variables.
Your proxy connection settings are stored in the env of the current user.
If you elevate to root via sudo, those connection settings do not appear anymore to apt-get. With the option, the env variable is kept the same for both your user and root, so apt-get can see your proxy settings.
You can compare what is defined using the following commands :
$env
$sudo env
$sudo -E env
Eshell sudo does not accept option
You are calling the Eshell built-in sudo. Do a
% which sudo
to see and look here: http://www.gnu.org/s/emacs/manual/html_node/eshell/Built_002dins.html.
You can do
% *sudo -E gmake install
to call the usual command.
Shell script with sudo sh
Please try just like this script line
sudo sh -c 'echo TEXT '$f1' TEXT > systemFile'
sudo bash -c 'echo TEXT '$f1' TEXT > systemFile'
i have use this able script line in .sh file and its working fine.
Related Topics
Resolve Relative Relocations in Partial Link
Libcurl Ssl Error After Fork()
Why Doesn't Linux Accept() Return Eintr
Undefined Reference to 'Pthread_Init' When Using -Lpthread Flag:
Interacting with Files from Multiple Directories via Bash Script
Write to Port 0Cf8H Fails with Segfault
How to Stop Apache from Listing the Contents of My User Directories
What Is the Use Case for Epollet
Bash Leftpad String with Spaces Inside Variable
Compile Git for 32-Bit Linux on Shared Hosting
Using Sed Replace Line in File with Another File
Error Cl_Device_Not_Available When Calling Clcreatecontext (Intel Core2Duo, Intel Ocl Sdk 3.0 Beta)
How Does Gdb Start an Assembly Compiled Program and Step One Line at a Time
Qserialport Cannot Open Tty After Application Has Previously Been Run by 'Root'
How to Draw 2D Diagram in Linux