Although most of you may know how to do this, it’s just a personal note for myself and for others who might get something out of it.
Everyone know the bash shell can be kickstarted with the bash command. These few switches make life a li’l more easier:
1. $ bash -r # creates a restricted bash shell where the $USER can’t move out of the home directory, even to a sub-directory
nits@excalibur:~$ ls -lF | grep -i documents
/
drwxr-xr-x 9 nits nits 4096 Dec 22 19:50 Documents
nits@excalibur:~$ bash -r
nits@excalibur:~$ cd Documents
bash: cd: restricted
nits@excalibur:~$ cd /mnt
bash: cd: restricted
nits@excalibur:~$ cd /var
bash: cd: restricted
2. $ bash -c <string> #runs a bash shell executing the string as a command. Note: It only spawns a bash shell to run the given command. That is, it only runs the command in the bash shell, doesn’t allow you to continue working with the bash shell after the command has finished executing.
nits@excalibur:~$ ksh
$ bash -c "ls -la | grep -i document"
drwxr-xr-x 9 nits nits 4096 Dec 22 19:50 Documents
$ exit
Note in the above example, that the bash shell is invoked only to execute the command (from KSH)
nits@excalibur:~$ ls -la Documents/ | grep -i scrip
drwxrwxr-x 2 nits nits 4096 Sep 12 18:41 scripts_and_config
nits@excalibur:~$ bash -c "cd Documents && ls -la | grep -i scr"
drwxrwxr-x 2 nits nits 4096 Sep 12 18:41 scripts_and_config
nits@excalibur:~$
This is another example where you can see that the bash shell is invoked only to execute the command (from within BASH)
3. $ bash -i # creates a new interactive bash shell, allowing you to do what you please
Source : thevoidghost[dot]wordpress[dot]com
0 comments:
Post a Comment