Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

350
Visualizações
while running this programe i occured one error as ambigous redirect

the following line in my bash script

cat >> $file_name 

give me this error:

./l7.sh: line 12: $file_name: ambiguous redirect

Here are the full code

https://github.com/vats147/public/blob/main/l7.sh

why?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Into the parameter file_name you must assign $1, which will pass to the current file as an input parameter.

#! /bin/bash

echo -e " Enter file name : \c"
read file_name=$1
if [ -f $file_name ]
then
    if [ -w $file_name ]
    then
        echo " type some text data. to quit press enter "
        #cat > $file_name(single angular bracket use for overwritten)
        #cat >> $file_name(two angular bracket use for appending a text)
        cat >> $file_name
    else
        echo " file not have write permission"      
    fi
else
    echo "file not exist"
fi

These are positional arguments of the script.

Executing ./script.sh Hello World will make

$0 = ./script.sh
$1 = Hello
$2 = World

Note

If you execute ./script.sh, $0 will give output ./script.sh but if you execute it with bash script.sh it will give output script.sh.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda