#๐ shell script for copying directory isn't working
97 messages ยท Page 1 of 1 (latest)
@fickle hill
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Did you verify your chmod worked?
Do ls -l and see. On some systems +x is restricted and you gotta add the x flag a different way (e.g. by specifying the full octal, not +x)
Also, instead of doing bash script with source command...
Just add shebang to your python file - put full path to your venv's python executable.
A python script doesn't need to have .py at the end. File extension is just help to suggest what should a file be opened with.
A lot of system tools are actually python stuff with shebang, just without the .py.
And THAT is a reason that +x is restricted by default on a lot of systems. Security. Running random command without knowing what it does can be dangerous, chmod changes file permissions so you shouldn't use it just like that without even learning its basics
Okay.. they just had that in the book so
Which book tells you to make bash scripts with source, instead of adding shebang to python file directly?
Automate the boring stuff
Can you link which page? I may message the author to suggest a change...
Weird. It seems Al (author) did an XY problem himself - knew how to do it for windows and then tried to "translate" it to Linux directly, when the solution was to just use linux stuff directly...
Wait.
The +x actually worked.
I just realised that "translation" Al did is why it doesn't work.
On Linux you gotta say "hey, this executable is in this folder, not in global folders"
You run it as ./ccwd instead of just ccwd
Ohh...
Meanwhile in windows, current folder is checked first for such stuff. And on Mac he did it as .command file which is Mac-specific thing.
(Mac would also work with a shell script and chmod +x, because Mac is unix-based.)
Yes. For that, you gotta add your Scripts folder to PATH.
Check if that was done somewhere in previous steps and you skipped it by accident.
I did add it
What I said here:
On Linux you gotta say "hey, this executable is in this folder, not in global folders"
You run it as./ccwdinstead of just ccwd
Those "global folders" is PATH.
Oh boy
Please show your PATH
I added Scripts/.venv/bin
๐
Need to remove this
Wait do I?
(.venv) atreus@pop-os:~$ $PATH bash: /home/atreus/Scripts/.venv/bin:/home/atreus/.cargo/bin:/home/atreus/.local/bin:/home/atreus/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin: No such file or directory
you forgot echo, that's why it said "no such file or directory" because it tried to run content of PATH as a command instead of just showing it ๐
Oh
Nah, that's because your venv is activated
Deactivate the venv
Okay
If book had you modify PATH with export command, that works only in that session.
You gotta modify your ~/.bashrc or ~/.profile to make that change to PATH work on every terminal you open
^
Bruhhh
There are so many ๐ญ
I said ~/.bashrc
The ~ means "your user's home"
The book says:
On Linux, add the following to the bottom of the .bashrc file:
export PATH=/home/al/Scripts:$PATH
If you run this command in terminal instead of adding it to the file, it worked only in that terminal until you closed it.
... Or if you added it to the .bashrc file but did not restart the terminal, the PATH wasn't reloaded. Restarting the terminal will work then
I did now
It opened the console
I don't know what I'm doing wrong
I changed the paths in shell script starting with shebangs
added Scripts to PATH
why did you use shebangs as the arguments to source and python3
that made them comments so you didnt actually pass arguments lol
also, you can just directly venv/bin/python3 the_script rather than activate+run+deactivate
venv was supposed to be be the path to your venv
and yeah it wont add it to your path, thats separate
how am i supposed to know what did you add?
what you should add to PATH to be able to run ~/Scripts/ccwd by just saying ccwd is ~/Scripts
echo $PATH /home/atreus/Scripts/.venv/bin:/home/atreus/.cargo/bin:/home/atreus/.local/bin:/home/atreus/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
you dont have /home/atreus/Scripts in it. what you have is /home/atreus/Scripts/.venv/bin (probally from the venv activation?)
Wait why isn't it added? I literally added it just a few
Oh
bruh
This feels so hectic
dealing with it for the first time yeah
Not a valid identifier
I'm so tired
I was excited of making a shell program today after learning this
uhh
are you running alpine or what
why do you have ash
oh, popos
ok so first of all you are supposed to add a directory to your PATH, not just set it to a path to 1 directory
secondly, the $ in $PATH is what we use to say that its an environment variable, but in shells thats already implied when you do VAR= something, so you just do export PATH="something", no $
to add rather than just set to new, we'll concatenate it with the old one
so it will be export PATH="$PATH:$HOME/Scripts"
(in the "" we need $ to tell the shell to expand the variable, otherwise it would just be a string literal)
so its kinda like PATH += ":/home/atreus/Scripts" or PATH.append("/home/atreus/Scripts") if you imagine that its already :-separated
there is also a case where you want to add it to the front to force it to come before some other thing, e.g. if you were activating a venv you'd want the venv to come before the system python
then you'd do export PATH="/the/venv:$PATH" (thats what .venv/bin/activate does, essentially, +some other stuff)
Automate the Boring Stuff. I commented a bit above that it seems like Al made himself an XY problem and "translated" Windows solution into bash, instead of using shebang in the python file directly
See the quote from the book I gave before I went afk.
It said exactly what export command to use...
And it said to add it to your .bashrc file in your user's home. Not to run it in terminal directly.
Here is the quote and explanation.
Steps what you need to do:
Just open your home folder, change visibility to show hidden files - then you'll see your .bashrc
Open it with any text editor.
Scroll to the bottom, add a new line with
export PATH=/home/atreus/Scripts:$PATH (I changed al to your username already)
Add an empty line at the end for good measure (some tools like when a file ends with an empty line).
Save.
Then open a new terminal window and echo $PATH
Yeah I'm getting the impression that a lot of the "devops" part of the book is of this general level of quality :/
I'm pretty sure Al is natively a Windows guy
Yoo, what's up guys? ๐
This is not a place to chat, this is someone's help thread (you're in #1035199133436354600).
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.