Estou tentando excluir o arquivo ~ $ bgka.mod do meu diretório atual
~
e $
são caracteres especiais no bash.
Você pode escapar usando \
ou colocar o argumento entre aspas simples '
.
Aspas duplas não podem ser usadas como "Incluindo caracteres entre aspas duplas "
preserva o valor literal de todos os caracteres entre aspas, com exceção de $
, 'e \"
Uso:
rm \~\$bgka.mod
Ou:
rm '~$bgka.mod'
Expansão de til
If a word begins with an unquoted tilde character
~
, all of the characters up to the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name. If this login name is the null string, the tilde is replaced with the value of theHOME
shell variable. IfHOME
is unset, the home directory of the user executing the shell is substituted instead. Otherwise, the tilde-prefix is replaced with the home directory associated with the specified login name.
Fonte Expansão da Shell
Expansão do Parâmetro da Shell
The
$
character introduces parameter expansion, command substitution, or arithmetic expansion. The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.
Fonte Expansão da Shell
Citação
Quoting is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to disable special treatment for special characters, to prevent reserved words from being recognized as such, and to prevent parameter expansion.
Each of the shell metacharacters has special meaning to the shell and must be quoted if it is to represent itself.
Escape Character
A non-quoted backslash
\
is the Bash escape character. It preserves the literal value of the next character that follows, with the exception of newline. If a \newline pair appears, and the backslash itself is not quoted, the \newline is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).Single Quotes
Enclosing characters in single quotes
'
preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.Double Quotes
Enclosing characters in double quotes
"
preserves the literal value of all characters within the quotes, with the exception of$
, ', and\
. The characters$
and ' retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters:$
, ',"
,\
, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash.
Fonte Citações :
Leitura Adicional
- Um índice A-Z da linha de comando do Bash para Linux - Uma excelente referência para todas as coisas relacionadas à linha de comando do Bash.
- ls - Lista informações sobre arquivos.
- citando :
- expansões de shell