1

If I define my archive folder it in my environment and export it, how do I access it in a shell script and run a program?

ARCHIVE=/home/kschmidt/public_html/CS265/Assignments/DrMath/Archive
export ARCHIVE
./prob1

Currently, my prob1 contains this code which I get an error when I try to run.

#!/bin/bash
print ARCHIVE
codeforester
  • 39,467
  • 16
  • 112
  • 140
Jeremy Wik
  • 63
  • 3

2 Answers2

1

You expand a shell variable by prefixing it with a $, and print it with echo or printf command - shell doesn't have a print command:

echo "$ARCHIVE"

or

printf '%s\n' "$ARCHIVE"

As an aside, it is not good to use relative paths (as in ./prob1) in a script, unless you are explicitly cding to the directory where prob1 exists. So, either:

  • do an explicit cd to the script directory before invoking it with a relative path

or

  • use an absolute path (as in /path/to/prob1)

Related:

codeforester
  • 39,467
  • 16
  • 112
  • 140
0

prob1's code should be like:

#!/bin/bash
bash $ARCHIVE

then prob1 run like this:

bash prob1

I hope this help.

Samiul Amin Shanto
  • 1,397
  • 9
  • 19