Solved

how do you keep $ dollar sign untouched within a script you touch by ssh?

Posted on 2010-09-01
3
539 Views
Last Modified: 2012-05-10
I have a script that needs altering via an ssh touch command.  Within this script is a $2 that needs to stay intact but the ssh command is thinking it's a variable and it disappears.  How do I keep this $ intact?  Here's my ssh command and code below:

You can see various $ within the script being edited.  The main ones like ${dir} are already good to go.  I'm mainly looking at lines 56-58 where it has    $2
rm /home/atest/www/.htaccess

touch /home/atest/public_html/"$dir".htaccess
echo "# $Id: .htaccess  1 2003/06/12 10:53:20 Michael Sasek$
#
# This is used with Apache WebServers
#
# For this to work, you must include the parameter 'Options' to
# the AllowOverride configuration
#
# Example:
#
# <Directory "/usr/local/apache/htdocs">
#   AllowOverride Options
# </Directory>
#
# 'All' with also work. (This configuration is in the
# apache/conf/httpd.conf file)

# The following makes adjustments to the SSL protocol for Internet
# Explorer browsers

<IfModule mod_setenvif.c>
  <IfDefine SSL>
    SetEnvIf User-Agent ".*MSIE.*" \
             nokeepalive ssl-unclean-shutdown \
             downgrade-1.0 force-response-1.0
  </IfDefine>
</IfModule>

# If Search Engine Friendly URLs do not work, try enabling the
# following Apache configuration parameter
#
# AcceptPathInfo On

# Fix certain PHP values
# (commented out by default to prevent errors occuring on certain
# servers)
#
<IfModule mod_php5.c>
  php_value session.use_trans_sid 0

</IfModule>
## SEO Url's .htaccess file
## If you want to use the Apache Mod-Rewrite method for SEO URL's
## Uncomment one of the two code blocks below, depending on where your store is installed:
## NOTE: This requires that you are on an apache web server with mod_rewrite enabled.

## If installed in a subfolder, uncomment the below block and change /folder/ to
## The directory where your shop is installed. For instance, if installed in the catalog directory
## Change it to /catalog/

RewriteEngine On
# Change "folder" to your catalog directory name
RewriteBase /${dir}
RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}

## If installed to the base home/root directory, uncomment the below code only:


## BOF change for dynamic pages stored in the database
RewriteRule index.html index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*).html$ information.php?page_alias=$1
## EOF change for dynamic pages stored in the database" > /home/atest/public_html/"$dir".htaccess

Open in new window

0
Comment
Question by:allwebnow
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 33579705
RewriteRule ^(.*)-p-(.*).html\$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html\$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-(.*).html\$ index.php?manufacturers_id=$2&%{QUERY_STRING}

which means: protect the concerned $ signs from being expanded by the shell using a backslash ( \ ) just in front of them.
Use this method to protect any character which needs it.

wmp

0
 

Author Comment

by:allwebnow
ID: 33579733
That was wonderful!  I knew it was something like that.  Just didn't know what the method character was.
0
 
LVL 9

Expert Comment

by:svs
ID: 33579762
Either use single quotes, or a here-document construct, like this:

cat > /home/atest/public_html/"$dir".htaccess <<"_EOF"
# $Id: .htaccess  1 2003/06/12 10:53:20 Michael Sasek$
#
# This is used with Apache WebServers
...
_EOF

See also http://tldp.org/LDP/abs/html/here-docs.html
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
centos linux 65 159
000webhost.com default error log 1 40
expand ext4 on centos 6 5 37
When trying to install php-fpm on CentOS 7 - GPG error 2 47
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question