1

I am trying to build a task automation script using python and for that, I am following a tutorial from youtube.

.my_commands.sh

#!/bin/bash

function create() {
    python create.py
    echo $1
}

create.py

print('Hello World')

and then in command prompt, I run this command create aditya which is supposed to print this according to tutorial.

Hello World
aditya

but instead it gives some error like this.

'create' is not recognized as an internal or external command,
operable program or batch file.

In the tutorial they were using mac system and i want to know is this possible to do the same on windows? If not why ?

5
  • 1
    I don't think this would work at all on a Mac either. Some parts of the code must have been missing. You must run my_commands.sh and somehow call the create() function within that Bash script. Commented Jan 2, 2020 at 6:13
  • This is the link of the tutorial youtube.com/… Commented Jan 2, 2020 at 6:20
  • @adityakumar : The error message says that you do not have an executable program or function named create. Did you source .my_commands.sh before trying to use your function? Commented Jan 2, 2020 at 8:10
  • @user1934428 I don't about source a file. Does that mean making it executable like we do in linux system using command chmod +x fileName ? Commented Jan 3, 2020 at 4:56
  • Which fileName are you talking about? You have in your posting only one file (.my_commands.sh), and since this file defines a function you want to use, it must be sourced by the shell which is supposed to use this function, and since it is a file to be sourced, you don't need x-bit. You also wouldn't need the #! line, though it is a good idea to have in, so that text editors can recognize what kind of syntax highlighting has to be applied. Commented Jan 3, 2020 at 7:34

2 Answers 2

1

You should try this to directly execute your script:

python3 create.py

Or in the terminal you can write

> source .my_commands.sh

After which you can execute the create command to get the output exactly as expected.

Sign up to request clarification or add additional context in comments.

Comments

0

The Windows native equivalent to a shellscript is a *.bat file, which has its own syntax (since powershell it is possible to use shellscript but it comes with some issues on its own).

You can run the python script directly from the command line

python create.py

1 Comment

While doing everything inside Python indeed sounds most reasonable for me too, the OP seemingly wants to try out the interaction between POSIX shell functions and Python and hence doesn't want to use BAT or Powershell anyway. You do have several implementations of shell languages available for Windows 10, so I think we should advise him in this direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.