0

I have a task which asks to write a script which displays all partitions formatted with a specific file system, given as parameter. I have written the script but when i run it it displays '0'. What am i doing wrong? This is my code:

#!/bin/bash
n=sudo parted -l | tail -n +8 | awk '{print $5}' | wc | awk '{print $2}'

m=sudo parted -l | tail -n +8 | awk '{print $5}'

q=sudo parted -l | tail -n +8

for i in $n; do
    if [ "[ $m | sed -n ip ]" = "$1" ]; then
        echo "$q | sed -n ip"
    fi
done
jww
  • 97,681
  • 90
  • 411
  • 885
Mary Poppins
  • 79
  • 13
  • 1
    https://www.shellcheck.net/ – tink Jan 17 '19 at 00:20
  • Possible duplicate of [How to debug a bash script?](https://stackoverflow.com/questions/951336/how-to-debug-a-bash-script) Also see [How to use Shellcheck](http://github.com/koalaman/shellcheck), [How to debug a bash script?](http://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](http://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](http://askubuntu.com/q/21136) (AskU), [Debugging Bash scripts](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html), etc. – jww Jan 17 '19 at 00:31

1 Answers1

0

Different approach from yours, but does it do what you need?

lsblk -f | awk '$0 ~ fs {print $NF}' fs=ext2
tink
  • 14,342
  • 4
  • 46
  • 50
  • Thank you, i know this could be done in a much easier way, but my problem is the way my script is written. I did use shell check and it displays an error concerning my 'i'. Do you have any idea what im doing wrong? – Mary Poppins Jan 17 '19 at 00:35
  • To being with your variable assignments are missing `n=$(sudo parted -l | tail -n +8 | awk '{print $5}' | wc | awk '{print $2}')` (the `$(` and `)` around them. – tink Jan 17 '19 at 00:41
  • @MaryPoppins The reason shellcheck is throwing up exceptions with your `i` as you put it - Is because you start a for loop, using `$i` as your iterator, but you don't actually use `$i` for anything. Is `$n` supposed to have multiple values? – itChi Jan 17 '19 at 09:44