Skip to main content
Became Hot Network Question
deleted 134 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 238

I just studying in Bash Scripting. And have exercise that can't resolve. What is going wrong? Can you help me?

It should doing next: ThisThis script should copy all files of which the names are provided as arguments on the command line to the users home directory. If no files have been provided, the script should use read to ask for file names, and copy all file names provided in the answer to the users home directory.

if [ -z $1 ]
then
    echo provide filenames
    read $FILENAMES
else
    FILENAMES="$@"
fi

echo the following filenames have been provided: $FILENAMES
for i in $FILENAMES
do
    cp $i $HOME
done

If I provide arguments as string - it works. But if I provide as "read $FILENAMES" - it has not working.

Mentor shows same solution in his lessons but did not shows how it works. enter image description here

Thank you for help.

UPDATE After I entered the filenames as arguments it gives empty strings and did not copy files to $HOME location

[dmytro@oc1726036122 ~]$ cd Desktop/
[dmytro@oc1726036122 Desktop]$ . totmp 
provide filenames
one two
the following filenames have been provided:
the following filenames have been provided:
[dmytro@oc1726036122 Desktop]$

I just studying in Bash Scripting. And have exercise that can't resolve. What is going wrong? Can you help me?

It should doing next: This script should copy all files of which the names are provided as arguments on the command line to the users home directory. If no files have been provided, the script should use read to ask for file names, and copy all file names provided in the answer to the users home directory.

if [ -z $1 ]
then
    echo provide filenames
    read $FILENAMES
else
    FILENAMES="$@"
fi

echo the following filenames have been provided: $FILENAMES
for i in $FILENAMES
do
    cp $i $HOME
done

If I provide arguments as string - it works. But if I provide as "read $FILENAMES" - it has not working.

Mentor shows same solution in his lessons but did not shows how it works. enter image description here

Thank you for help.

UPDATE After I entered the filenames as arguments it gives empty strings and did not copy files to $HOME location

[dmytro@oc1726036122 ~]$ cd Desktop/
[dmytro@oc1726036122 Desktop]$ . totmp 
provide filenames
one two
the following filenames have been provided:
the following filenames have been provided:
[dmytro@oc1726036122 Desktop]$

This script should copy all files of which the names are provided as arguments on the command line to the users home directory. If no files have been provided, the script should use read to ask for file names, and copy all file names provided in the answer to the users home directory.

if [ -z $1 ]
then
    echo provide filenames
    read $FILENAMES
else
    FILENAMES="$@"
fi

echo the following filenames have been provided: $FILENAMES
for i in $FILENAMES
do
    cp $i $HOME
done

If I provide arguments as string - it works. But if I provide as "read $FILENAMES" - it has not working.

Mentor shows same solution in his lessons but did not shows how it works. enter image description here

UPDATE After I entered the filenames as arguments it gives empty strings and did not copy files to $HOME location

[dmytro@oc1726036122 ~]$ cd Desktop/
[dmytro@oc1726036122 Desktop]$ . totmp 
provide filenames
one two
the following filenames have been provided:
the following filenames have been provided:
[dmytro@oc1726036122 Desktop]$
edited tags
Link
muru
  • 78.1k
  • 16
  • 213
  • 319
UPDATE
Source Link
Smenov
  • 147
  • 1
  • 2
  • 8

I just studying in Bash Scripting. And have exercise that can't resolve. What is going wrong? Can you help me?

It should doing next: This script should copy all files of which the names are provided as arguments on the command line to the users home directory. If no files have been provided, the script should use read to ask for file names, and copy all file names provided in the answer to the users home directory.

if [ -z $1 ]
then
    echo provide filenames
    read $FILENAMES
else
    FILENAMES="$@"
fi

echo the following filenames have been provided: $FILENAMES
for i in $FILENAMES
do
    cp $i $HOME
done

If I provide arguments as string - it works. But if I provide as "read $FILENAMES" - it has not working.

Mentor shows same solution in his lessons but did not shows how it works. enter image description here

Thank you for help.

UPDATE After I entered the filenames as arguments it gives empty strings and did not copy files to $HOME location

[dmytro@oc1726036122 ~]$ cd Desktop/
[dmytro@oc1726036122 Desktop]$ . totmp 
provide filenames
one two
the following filenames have been provided:
the following filenames have been provided:
[dmytro@oc1726036122 Desktop]$

I just studying in Bash Scripting. And have exercise that can't resolve. What is going wrong? Can you help me?

It should doing next: This script should copy all files of which the names are provided as arguments on the command line to the users home directory. If no files have been provided, the script should use read to ask for file names, and copy all file names provided in the answer to the users home directory.

if [ -z $1 ]
then
    echo provide filenames
    read $FILENAMES
else
    FILENAMES="$@"
fi

echo the following filenames have been provided: $FILENAMES
for i in $FILENAMES
do
    cp $i $HOME
done

If I provide arguments as string - it works. But if I provide as "read $FILENAMES" - it has not working.

Mentor shows same solution in his lessons but did not shows how it works. enter image description here

Thank you for help.

I just studying in Bash Scripting. And have exercise that can't resolve. What is going wrong? Can you help me?

It should doing next: This script should copy all files of which the names are provided as arguments on the command line to the users home directory. If no files have been provided, the script should use read to ask for file names, and copy all file names provided in the answer to the users home directory.

if [ -z $1 ]
then
    echo provide filenames
    read $FILENAMES
else
    FILENAMES="$@"
fi

echo the following filenames have been provided: $FILENAMES
for i in $FILENAMES
do
    cp $i $HOME
done

If I provide arguments as string - it works. But if I provide as "read $FILENAMES" - it has not working.

Mentor shows same solution in his lessons but did not shows how it works. enter image description here

Thank you for help.

UPDATE After I entered the filenames as arguments it gives empty strings and did not copy files to $HOME location

[dmytro@oc1726036122 ~]$ cd Desktop/
[dmytro@oc1726036122 Desktop]$ . totmp 
provide filenames
one two
the following filenames have been provided:
the following filenames have been provided:
[dmytro@oc1726036122 Desktop]$
Source Link
Smenov
  • 147
  • 1
  • 2
  • 8
Loading