I'm trying to write a script that takes a string and then looks for all instances of that string a a file. When I run the command outside of the script it runs perfectly but if I try to run it in the script is says that the file doesn't exist. Here is my code
if [ "$#" -eq 0 ]; then echo "Please enter an argument" else $result=`grep $1 Sales.csv` echo $result fiAnd yes the file is called Sales.csv. I would have thought it was something to do with the format of the file but the command works outside of the script which is why I'm confused
Edit: Should have mentioned that I'm running the linux from virtualBox
71 Answer
When assigning a variable you just put whatever you want as the variable minus the $. Putting the $ in front of the variable makes it the output of the variable. Since the variable isn't defined in the script yet the line should be:
result=$(grep $1 /some/path/to/Sales.csv)Then calling the variable next like:
echo $resultHope this helps!