0

I have a python file which works fine. It takes a file and does something on it. So I run it like this:

./MyPy.py File.txt

Then with bash script I grep some part of it.

./MyPy.py File.txt | grep -vE "^color"

So what I want to do is creating a bash file which asks the user for the path of the File and does ./MyPy.py File.txt | grep -vE "^color" in it and gives the result to out put.

Can you please help me with this ?

3
  • So you want to read the file name at run time into a variable? Have you tried using read? Look in the bash manual. Commented Apr 30, 2015 at 13:24
  • 3
    why not just use re and do it all in python? Commented Apr 30, 2015 at 13:27
  • Hi guys, Padraic: Cuz I had to do it in bash. Tom: Thanks, read worked for me :) Commented May 3, 2015 at 11:37

1 Answer 1

3

This should work:

#!/bin/bash
read -e -p "Enter the path of the file: " file
./MyPy.py "$file" | grep -vE "^color"

Additional improvement:

If you want to interpret ~ as /home/user i.e use ~/Downloads to point to /home/user/Downloads, then:

#!/bin/bash
read -e -p "Enter the path of the file: " file
file=${file/#\~/$HOME}
./MyPy.py "$file" | grep -vE "^color"
Sign up to request clarification or add additional context in comments.

1 Comment

eval can also be used to do a second scan to translate the ~, but eval is evil.

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.