linux - I can't get my bash script to run -


this script used not run, hoping can me figure out issue is. new unix

#!/bin/bash  # cat copyit  # copies files   numofargs=$# listoffiles= listofcopy=   # capture of arguments passed command, store of                     arguments, except # last (the destination)   while [ "$#" -gt 1 ] listoffiles="$listoffiles $1" shift done  destination="$1"   # if there less 2 arguments entered, or if there          more 2 # arguments, , last argument not valid directory, display # error message   if [ "$numofargs" -lt 2 -o "$numofargs" -gt 2 -a ! -d "$destination" ] echo "usage: copyit sourcefile destinationfile" echo" copyit sourcefile(s) directory" exit 1 fi   # @ each sourcefile   fromfile in $listoffiles   # see if destination file directory   if [ -d "$destination" ] destfile="$destination/`basename $fromfile`" else destfile="$destination" fi   # add file copy list if file not exist, or # user # says file can overwritten    if [ -f "$destfile" ]  echo "$destfile exist; overwrite it? (yes/no)? \c" read ans  if [ "$ans" = yes ] listofcopy="$listofcopy $fromfile" fi  else listofcopy="$listofcopy $fromfile" fi done   # if there copy - copy   if [ -n "$listofcopy" ] mv $listofcopy $destination fi 

this got , seems script didn't execute though did invoke it. hoping can me

[taniamack@localhost ~]$ chmod 555 tryto.txt [taniamack@localhost ~]$ tryto.txt bash: tryto.txt: command not found... [taniamack@localhost ~]$ ./tryto.txt ./tryto.txt: line 7: $'\r': command not found ./tryto.txt: line 11: $'\r': command not found ./tryto.txt: line 16: $'\r': command not found ./tryto.txt: line 43: syntax error near unexpected token `$'do\r'' '/tryto.txt: line 43: `do 

looks file contains windows new line formatting: "\r\n". on unix, new line "\n". can use dos2unix (apt-get install dos2unix), convert files.

also have @ chmod manual (man chmod). of time use chmod +x ./my_file give execution rights


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -