-1

I am wondering is there is a way to assign a regular expression as a character in a string to a variable and not have the regular expression change my variable.

For example: in my directory I am working on I have: A.cc, A.hh, and foo.sh.

In foo.sh:

var=$(A*)

echo $var

I am trying to assign to var specifically A* and not A.cc, A.hh, which is what happening with *.

I am using /bin/sh.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
ucr
  • 1
  • 1
    use `var=A*; printf "%s\n" "$var"`. see: [What is $() in a command?](https://unix.stackexchange.com/questions/147420/what-is-in-a-command), [Why does my shell script choke on whitespace or other special characters?](http://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters) and [Why is printf better than echo?](https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo) – Evgeny Vereshchagin Aug 09 '15 at 04:53

1 Answers1

1

use quotes to stop bash from globbing.

var="A*"
echo "$var"
Jasen
  • 3,715
  • 13
  • 14