0

Currently I have a file called coding.sh containing:

#!/usr/bin/env bash

echo "to programming folder"
cd /home/jchong/Documents/Programming

I have tried the sudo chmod +x coding.sh command, changing /home/jchong/ with $HOME or ~,changing what is after the #!, and ensuring the spelling is correct. However when running ./coding.sh the pwd does not change. Also, I am running this all in my anaconda environment called base. Was wondering if you guys could please help me out?

James Chong
  • 371
  • 2
  • 16
  • Not possible because each program has its own cd. And your shell script is its own program. You might consider using `alias` instead, to set up shortcuts in your shell. – user253751 Feb 03 '23 at 01:49
  • 1
    @user253751 There's almost never a situation when an alias is a better choice than a shell function. Aliases don't work in scripts. They can't accept arguments except in terminal position. Doing conditional logic in them, when possible at all, involves ugly hacks. They aren't even guaranteed to be an available feature at all in the first place if your shell is compiled without interactive extensions. etc. One of the categories of questions we get over and over is people having problems because they're trying to use an alias for something only a function can do. Please don't contribute. – Charles Duffy Feb 03 '23 at 02:06
  • @user253751 Sure, but you only type a shell function once. The difference in length between `alias f='...'` and `f() { ...; }` -- what are you saving exactly? And once they're defined the usage is exactly the same. – Charles Duffy Feb 03 '23 at 02:10

0 Answers0