0

I have a cache in the filesystem which I implemented this way.

  1. To store a value I do something like

    echo ""$KEY1"_"$KEY2"="$VALUE" >> $CACHE_DIR/$INDEX.cache
    
  2. To get a value, first I source the cache file:

    source $CACHE_DIR/$INDEX.cache
    

    and then I echo the "$KEY1"_"$KEY2"

Cache example:

foo1_foo2=wohohhowwho

The problem with this, is that I have some keys that have a "/" in it, so when I have this:

foo3_foo/4=wohohhowwho

and source the file, it says

cache/15637.cache: line 1: foo3_foo/4=wohohhowwho: No such file or directory

because of the /.

Is there an option to the source command to not search in the path for files and only take in count the content as vars? I could escape the /, but is there another way?

2
  • You seem to be confusing bash scripts with a storage mechanism... Commented Oct 24, 2012 at 16:05
  • I'm not confusing anything, I use a cache that works fine for me. I only have one case with problems. Thanks anyway Commented Oct 24, 2012 at 16:18

2 Answers 2

2

There is no other way since / is not allowed as a character in bash variables.

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

Comments

1

you have to ``sanitize'' you key as bash only support for variable name: letter, digit and the underline character.

KEY1=${KEY1//\//_}
KEY2=${KEY2//\//_}

Comments

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.