When I am assigning .* to a variable , it is assigning all hidden files.  [root@s1 ~]# a=".*" [root@s1 ~]# echo $a . .. .bash_history .bash_logout .bash_profile .bashrc .cache .config .cshrc .history .lesshst .mozilla .pki .rnd .ssh .tcshrc .viminfo .virsh .xauth6SHzeY .xauthhAVYfm .xauthI6Cte3 .xauthk7ea35 .xauthlXtiZ9 .Xauthority .xauthQm7mJ8 .xauthTpWbxP .xauthY9KsdC   I expect below output :      .*   How to escape it, thanks.  I tried below and it gives output    [root@s1 ~]# a='".*"'     [root@s1 ~]# echo $a     ".*"      ".*"   but not      .*
1847
Or, an introductory guide to robust filename handling and other string passing in shell scripts.  I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names).  I encountered a problem such as the following:   I have a file name containing a space hello world, and it was treated as two separate files hello and world. I have an input line with two consecutive spaces and they shrank to one in the input. Leading and trailing whitespace disappears from input lines. Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is is actually the name of files. There is an apostrophe ' (or a double quote ") in the input and things got weird after that point. There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).   What is going on and how do I fix it?
31808
I often have to do a recursive search in files. Tired of typing the whole "find/grep" combination all the time, I just created a script with the following line:  find . -name $1 -exec grep $2 {} + 2&gt;/dev/null   The idea is that I should be able to run it as, for example:  myfind '*' hello   The problem is, when '*' gets passed into the script, the script is expanding it to each file in the directory.  I tried putting a quote around $1:   find . -name '$1' -exec grep $2 {} + 2&gt;/dev/null   However, this turns $1 into a literal string.  Would appreciate your help in finding the right syntax. Must be something simple that I am missing.
26950
Firstly my main goal is to try and get FTP files recursively in Centos.  However the actual FTP login contains an @ which ruins the syntax.  Is there some way to place the username in "double quotes" or some such equivalent such that I can use @in the username?
52855
# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/bash/examples/startup-files for examples. # the files are located in the bash-doc package.  # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022  # if running bash if [ -n "$BASH_VERSION" ]; then     # include .bashrc if it exists     if [ -f "$HOME/.bashrc" ]; then     . "$HOME/.bashrc"     fi fi  # set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then     PATH="$HOME/bin:$PATH" fi   Can anyone explain the contents of the ~/.profile file? So when you enter into the ~/.profile file what does all the writing mean?
113290
I have PATH=foo set in /etc/profile  According to /etc/password the root and myaccount users have /bin/bash as the login shell.  When I log in as myaccount, the PATH has been set correctly from /etc/profile. If I then sudo su, PATH does not include the value set in /etc/profile.  If I sudo su - instead then /etc/profile is sourced. I know it is good practice to do this anyway but I don't see why it's necessary in order to source /etc/profile.  Why does sudo su clobber PATH, disregarding /etc/profile and how to I make it not?
39077
In my Bash environment I use variables containing spaces, and I use these variables within command substitution. What is the correct way to quote my variables? And how should I do it if these are nested? DIRNAME=$(dirname &quot;$FILE&quot;)  or do I quote outside the substitution? DIRNAME=&quot;$(dirname $FILE)&quot;  or both? DIRNAME=&quot;$(dirname &quot;$FILE&quot;)&quot;  or do I use back-ticks? DIRNAME=`dirname &quot;$FILE&quot;`  What is the right way to do this? And how can I easily check if the quotes are set right?
21256
I'd like to find a Windows batch counterpart to Bash's $@ that holds a list of all arguments passed into a script.   Or I have to bother with shift?
10776
I know these are few special variables used by bash. But I am not able to understand them. Can anyone explain what these variables are and how to use them?  $*  $@  $#
102236
I have a file with the following permissions on my MacBook Pro:  -rwxr-xr-x@  1 root  wheel   101K Feb 29 17:09 apachectl  What does the @ stand for?  I can't execute the file and this is the only thing that's standing out to me.  How can I get rid of it?    Just as some background, I copied this from a Time Machine backup.
45221
&gt; echo "hi" hi &gt; VAR='echo "hi"' &gt; $VAR "hi"   Why is the output of the above commands different?  A similar thing occurs with single quotes:  &gt; VAR="echo 'hi'" &gt; $VAR &gt; 'hi'
106364
For example, while this works:   $ echo foo foo   This doesn't:   $ /bin/sh -c echo foo    Whereas this does:   $ /bin/sh -c 'echo foo; echo bar' foo bar   Is there an explanation?
101133
Some of the files in my directories under Linux have a . at the end of the permissions listing.     What does the dot mean at the end of -rw-r--r--?  How do you set it with chmod?
95665
Why is it that find prints out a leading ./ to results if no paths are given?  $ find ./file1 ./file2 ./file3   What is the reason for not printing out this?  $ find file1 file2 file3
37028
If you copy the contents of   httpd.conf   and then paste it into a cat command.. such as this one..  #!/bin/bash cat &gt; /test &lt;&lt; EOF pasted here.. EOF   you run into this error:  -bash: command substitution: line 1: unexpected EOF while looking for matching `'' -bash: command substitution: line 4: syntax error: unexpected end of file   perhaps the solution is to escape the dollar signs and maybe even quotes and so on..  but given that this is such a large file.. can dollar signs be automatically be escaped ?  is my only option to escape them via another program and then give it to the cat command ?
68210
There is apparently a vulnerability (CVE-2014-6271) in bash:   I am trying to figure out what is happening, but I'm not entirely sure I understand it. How can the echo be executed as it is in single quotes?  $ env x='() { :;}; echo vulnerable' bash -c "echo this is a test" vulnerable this is a test     EDIT 1: A patched system looks like this:  $ env x='() { :;}; echo vulnerable' bash -c "echo this is a test" bash: warning: x: ignoring function definition attempt bash: error importing function definition for `x' this is a test   EDIT 2: There is a related vulnerability / patch:  which uses a slightly different test:  $ env 'x=() { :;}; echo vulnerable' 'BASH_FUNC_x()=() { :;}; echo vulnerable' bash -c "echo test"   unpatched output:  vulnerable bash: BASH_FUNC_x(): line 0: syntax error near unexpected token `)' bash: BASH_FUNC_x(): line 0: `BASH_FUNC_x() () { :;}; echo vulnerable' bash: error importing function definition for `BASH_FUNC_x' test   partially (early version) patched output:  bash: warning: x: ignoring function definition attempt bash: error importing function definition for `x' bash: error importing function definition for `BASH_FUNC_x()' test   patched output up to and including CVE-2014-7169:  bash: warning: x: ignoring function definition attempt bash: error importing function definition for `BASH_FUNC_x' test   EDIT 3: story continues with:
100638
As a simple example, I have a bunch of source code files. I want to store the "head" command output to a variable for all these files.  I tried:  output=$(head $file)   but what happened is that this automatically trimmed all \n characters when storing the output to a variable.  How do I store the command output as is without removing \n characters?
27654
I have a script which finds files in the directory specified by user.    #!/bin/bash  # make sure about the correct input if [ -z $1 ] then     echo "Usage: ./script_name.sh    path/to/directory" else     DIR=$1     if [ $DIR = '.' ]     then          echo "Find files in the directory $PWD"     else           echo "Find files in the directory $DIR"     fi      find $DIR -type f -exec basename {} \;  fi   if I input    $ ./script_name.sh .   script gives me correct substitution ./ to $PWD and shows (for example)    $ Find files in the directory /root/scripts     But I can't make a decision how to substitute ../ to the name of the directory  immediately above in the hierarchy.  If I input    $ ./script_name.sh ..     script gives me the output    $ Find files in the directory ..     Does anybody know how to substitute ../ to the actual name of the directory?