L in u X ba sics for h acke rs g e t t I n g s t a r t e d w I t h


How Not to Add to the PATH Variable


Download 7.3 Mb.
Pdf ko'rish
bet83/115
Sana27.10.2023
Hajmi7.3 Mb.
#1728481
1   ...   79   80   81   82   83   84   85   86   ...   115
Bog'liq
linuxbasicsforhackers

How Not to Add to the PATH Variable
One mistake commonly made by new Linux users is assigning a new direc-
tory, such as /root/newhackingtool, directly to the 
PATH
variable in this way:
kali >PATH=/root/newhackingtool
kali >echo $PATH
/root/newhackingtool
If you use this command, your 
PATH
variable will only contain the /root/
newhackingtool directory and no longer contain the system binaries direc-
tories such as /bin/sbin, and others that hold critical commands. When 
you then go to use any of the system commands, you’ll receive the error 
command not found
, as shown next, unless you first navigate to the system 
binaries directory when you execute the command:
kali >ls
bash: ls: command not found
Remember that you want to append to the 
PATH
variable, not replace it. 
If you’re in doubt, save the contents of the variable somewhere before you 
modify it.
Creating a User-Defined Variable
You can create your own custom, user-defined variables in Linux by simply 
assigning a value to a new variable that you name. This may be useful when 
you are doing some more advanced shell scripting or find you’re often using 
a long command that you get tired of typing over and over.


78
Chapter 7
The syntax is straightforward: enter the name of your variable, followed 
by the assignment symbol (
=
) without a space, and then the value to put in 
the variable, as shown here:
kali >MYNEWVARIABLE="Hacking is the most valuable skill set in the 21st century"
This assigns a string to the variable 
MYNEWVARIABLE
. To see the value in 
that variable, use the 
echo
command and the 
$
content symbol with the vari-
able name, as we did earlier:
kali >echo $MYNEWVARIABLE
Hacking is the most valuable skill set in the 21st century
Just like our system environment variables, user-defined variables must 
be exported to persist to new sessions.
If you want to delete this new variable, or any variable, use the 
unset
command. Always think before deleting a system variable, though, because 
your system will probably operate much differently afterward.
kali >unset MYNEWVARIABLE
kali >echo $MYNEWVARIABLE
kali >
As you can see, when you enter 
unset MYNEWVARIABLE
, you delete the vari-
able along with its value. If you use 
echo
on that same variable, Linux will 
now return a blank line.
Summary
You might find environment variables foreign, but it’s worth getting to know 
them. They control how your working environment in Linux looks, acts, 
and feels. You can manage these variables to tailor your environment to 
your needs by changing them, exporting them, and even creating your own. 
In some cases, they may be useful for covering your tracks as a hacker.


Managing User Environment Variables

Download 7.3 Mb.

Do'stlaringiz bilan baham:
1   ...   79   80   81   82   83   84   85   86   ...   115




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling