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
|
linuxbasicsforhackers
- Bu sahifa navigatsiya:
- Creating a User-Defined Variable
- MYNEWVARIABLE="Hacking is the most valuable skill set in the 21st century"
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. |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling