0

Below is the sample shell script for deleting apps from cloud foundry. This works in Windows machine but failing in Mac book. Can someone help on this?

#!/bin/bash  
read -p "Enter your ID:" uid
echo
read -sp "Enter your password:" pwd
echo


cf login -a test.net -u $uid -p $pwd -o TEST1 -s Space1

file=test.txt
for i in `cat $file`
do
cf delete "$i" -f -r
done
  • 4
    Lots of bugs here http://shellcheck.net/ will catch -- start there. – Charles Duffy Jun 22 '23 at 00:12
  • 2
    Also, "fails" or "failing" is not a problem description. You have to describe _what specific part_ fails; a problem reading inputs is different from a problem parsing files is different from... etc, etc. – Charles Duffy Jun 22 '23 at 00:12
  • Why is this tagged `python`? – chepner Jun 22 '23 at 00:13
  • 1
    See also [DontReadLinesWithFor](https://mywiki.wooledge.org/DontReadLinesWithFor) re: the use of ```for i in $(cat file)``` or its antique backtick equivalent., all of which are buggy. – Charles Duffy Jun 22 '23 at 00:15
  • 1
    It's also a good place to start to use `bash -x yourscript` or add `set -x` within the script to turn on trace logging, and to read through that log to see how the commands actually being run differ from what you expect. For example, tools on Windows are more likely to silently ignore DOS newlines than those elsewhere, meaning one problem you _could_ be hitting is [Are shell scripts sensitive to encoding and line endings?](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) – Charles Duffy Jun 22 '23 at 00:15
  • 3
    My crystal ball tells me that the file was copied from Windows and has CRLF line breaks. You need to remove the `\r` characters. – Barmar Jun 22 '23 at 00:30
  • @CharlesDuffy Thanks a lot. Below one helped and i figured it out. Lots of bugs here shellcheck.net will catch -- start there – Tamilselvan Jun 22 '23 at 02:24

0 Answers0