-1
#!/bin/bash
echo "changing directory"
cd ~/Downloads/Burpsuite

hello! I don't know any of the commands of bash scripting but want to learn and I am not getting any of the good resources so I thought to post question here.

1.So basically the ques is how can I change to burpsuite directory in bash script like we do in terminal (linux).

  1. Can you also please tell me the command in windows for same.

3.can you also tell me how can I run a program in same bash language

    #!/bin/bash
echo "changing directory"
python3 dirserach.py

Like this if possible please give short commands

Thanku ,.......

David C. Rankin
  • 75,900
  • 6
  • 54
  • 79
  • 1
    A child process cannot change the environment of its parent-process (including `$PWD` - the present working directory). When you run a script, the script is the child-process for the shell running your terminal. You cannot change the current directory of the shell by running a script. When you call a program within a script (like `python3 dirserach.py`), your script creates another child-process (subshell) in which the program runs) – David C. Rankin Feb 06 '22 at 08:24
  • Perhaps see also [What exactly is current working directory?](https://stackoverflow.com/questions/45591428/what-exactly-is-current-working-directory/66860904) – tripleee Feb 06 '22 at 09:22

1 Answers1

0

All terminals commands are same as running the same in the bash script. If you note bash is also know as Bourne Again Shell.

Thus, use cd to change directory in bash (in windows too it's the same). If you need to run the bash script, simply run it using (if the name of the script is script.sh

bash script.sh

Also, please note that it is not possible for you to replace terminal commands with a script to change directories (in the terminal). The directory that gets changed via any script run in a terminal is only effective in the child processes of the parent.

To my understanding, the question entails that we want to change the directory to facilitate running the python script. If the case is as pointed out by @david, in the comments, the best approach is to use an alias such as alias cd_project=cd any_path

  • 1
    Recall the rule: A child-process cannot change the environment of its parent (including the `PWD`) – David C. Rankin Feb 06 '22 at 08:26
  • Don't we need to change the environment of the child here. The OP needs to change the directory to run the `python` script, which is a child-process here. – Abdullah Khilji Feb 06 '22 at 08:45
  • Changing and making use of a changed directory in the child is fine. I may be reading the question wrong, but by my read, the OP is asking how to change the directory in the child and have that change effect the parent (terminal) process. Granted, the question is less than 100% clear -- likely due to a native language difference -- so I can't say for sure which interpretation is correct. – David C. Rankin Feb 06 '22 at 09:19
  • Please don't answer common duplicate questions. – tripleee Feb 06 '22 at 09:22