#๐Ÿ”’ shell script for copying directory isn't working

97 messages ยท Page 1 of 1 (latest)

fickle hill
#

I don't get what I did wrong. I just copy-pasted code from the book(ATBS)

main crestBOT
#

@fickle hill

Python help channel opened

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.

fickle hill
#

Changed the path to absolute path instead of relative. It's still not working..

ruby ferry
#

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)

fickle hill
#

Oh

#

I honestly don't know what chmod means

#

Just looked up

ruby ferry
#

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.

fickle hill
#

??

#

uh

ruby ferry
# fickle hill I honestly don't know what chmod means

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

fickle hill
#

Okay.. they just had that in the book so

ruby ferry
#

Which book tells you to make bash scripts with source, instead of adding shebang to python file directly?

fickle hill
#

Automate the boring stuff

ruby ferry
#

Can you link which page? I may message the author to suggest a change...

ruby ferry
#

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...

ruby ferry
# fickle hill

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

fickle hill
#

Ohh...

ruby ferry
#

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.)

fickle hill
#

Okay

#

it's not working in other directories

ruby ferry
#

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.

fickle hill
#

I did add it

ruby ferry
#

What I said here:

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

Those "global folders" is PATH.

fickle hill
#

Oh boy

ruby ferry
fickle hill
#

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

ruby ferry
fickle hill
#

Oh

ruby ferry
#

Deactivate the venv

fickle hill
#

Okay

ruby ferry
#

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

fickle hill
#

Okay

#

uhhh

fickle hill
#

There are so many ๐Ÿ˜ญ

ruby ferry
fickle hill
#

Oh

#

My bad

ruby ferry
#

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

fickle hill
#

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

ionic quarry
#

why did you use shebangs as the arguments to source and python3

#

that made them comments so you didnt actually pass arguments lol

fickle hill
#

Bruh

#

....

#

I'm stupid

ionic quarry
#

also, you can just directly venv/bin/python3 the_script rather than activate+run+deactivate

fickle hill
#

okaty

#

I don't get what to do now

#

Still not showing

ionic quarry
#

venv was supposed to be be the path to your venv
and yeah it wont add it to your path, thats separate

fickle hill
#

So what did I add to my $PATH now?

ionic quarry
#

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

fickle hill
#

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

ionic quarry
#

you dont have /home/atreus/Scripts in it. what you have is /home/atreus/Scripts/.venv/bin (probally from the venv activation?)

fickle hill
#

Wait why isn't it added? I literally added it just a few

#

Oh

#

bruh

#

This feels so hectic

ionic quarry
#

dealing with it for the first time yeah

fickle hill
#

Not a valid identifier

#

I'm so tired

#

I was excited of making a shell program today after learning this

#

uhh

ionic quarry
#

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)

fickle hill
#

I need a min to deal with this

ruby ferry
ruby ferry
# fickle hill

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.

ruby ferry
# ruby ferry The book says: > On Linux, add the following to the bottom of the .bashrc file: ...

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

abstract copper
#

I'm pretty sure Al is natively a Windows guy

burnt geyser
#

Yoo, what's up guys? ๐Ÿ˜„

ruby ferry
main crestBOT
#
Python help channel closed for inactivity

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.