Читать книгу Kali Linux Penetration Testing Bible - Gus Khawaja - Страница 69
Commands Variable
ОглавлениеSometimes, you might want to execute commands and save their output to a variable. Most of the time, the goal behind this is to manipulate the contents of the command output. Here's a simple command that executes the ls
command and filters out the filenames that contain the word simple using the grep
command. (Don't worry, you will see more complex scenarios in the upcoming sections of this chapter. For the time being, practice and focus on the fundamentals.)
#!/bin/bash LS_CMD=$(ls | grep 'simple') printf "$LS_CMD\n"
Here are the script execution results:
root@kali:/opt# simplels.sh simpleadd.sh simplels.sh