Question

Write a bash script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. I...

Write a bash script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. It should output a list of integers from 'a' and ending with '1' according to the following iteration rule. ( fx = x/2 if x is even; fx=3x+1 if x is odd )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/bash

if [ $# -ne 1 ]

then

echo "You need to enter one argument"

else

echo "You have entered" $1

value="$1"

i=0

while [ $value -gt 1 ]

do

rem=$(( $value % 2 ))

if [ $rem -eq 0 ]

then

value=$(( value / 2 ))

array[$i]=$value

else

value=$((( 3 * value) + 1))

array[$i]=$value

fi

i=$((i+1))

done

echo ${array[@]}

fi

Code and output:

11:50 AM Terminal Open Save 1 #!/bin/bash vipul@ubuntu: ~/shell 3 if S# - ne 1 ] vipul@ubueentu : ~/shell$ chmod 755 series.s

Add a comment
Know the answer?
Add Answer to:
Write a bash script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a bash script question.sh that accepts one command line argument which is supposed to be...

    Write a bash script question.sh that accepts one command line argument which is supposed to be a positive integer n. The script should print all odd integers from 1 through n. Write a C or C++ program question.c(pp) to read from stdin as many integers as there are available and then print the squares of all these integers. You should test your code by “./question.sh <n> | ./question” assuming the compiled C/C++ program is question. See the following for a...

  • Write a C++ program that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60...

    Write a C++ program that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 49 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to square all 60 array elements. You should divide this update task among the n threads as evenly as possible. Print the array both before and after the update separately as...

  •  Write a Perl script that accepts exactly 2 integer arguments where the first argument must...

     Write a Perl script that accepts exactly 2 integer arguments where the first argument must be less than the second argument. The script will print a comma separated list of integers starting with the first argument up through the second argument.  The last printed value should be the second command line argument not be followed by a comma.  The script should also be able to handle the following errorsituations: o incorrect number of arguments o the first...

  • Unix classes Write a bash script that take in three integer numbers from the command line...

    Unix classes Write a bash script that take in three integer numbers from the command line and print out the sum and the average. Name the script awesum.sh hb1170uxb4:~$ ./awesum.sh 100 200 300 sum: 600 average: 200 hb1170uxb4: ~S

  • LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command...

    LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...

  • Java Programming Write a method named isEven that accepts an integer argument. The method should return...

    Java Programming Write a method named isEven that accepts an integer argument. The method should return true if the argument is even, or false if not. The program’s main method should use a loop to generate a random integer. The number of random integers is provided by a user, who must enter a number greater than 10. The loop should then invoke the isEven method to determine whether each integer is even or odd, display the random number and the...

  • Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusi...

    Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string (‘A’<->’Z’, ‘B’<->’Y’, ‘C’<->’X’, etc). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before...

  • Write a Bash script called hello that uses command line arguments to allow the user to...

    Write a Bash script called hello that uses command line arguments to allow the user to put two strings after the command name, when the script is being executed. These strings should represent a first and last name. The script should then write out a greeting to the user that includes the first and last name. Here is an example of how the script might work (the first line represents what the user types to launch the script): [user@HAL] hello...

  • 1. (50 pts) Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer...

    1. (50 pts) Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string ('A'<>'Z', 'B'<->'Y', 'C''X', etc). You should divide this conversion task among the n threads as evenly as possible, Print out the...

  • In Bash Write two scripts, 'backup.sh' and 'restore.sh' which do the following: backup.sh accepts a list...

    In Bash Write two scripts, 'backup.sh' and 'restore.sh' which do the following: backup.sh accepts a list of arguments which indicate the name o the output file and a list of files that should be backed up. Will take all of the files provided oher than the first and create a tar-ball(a tarred, gzipped file) with the name provided in the first argument. restore.sh Accepts a single filename of a tar-ball created by the script above and restores the files from...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT