Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

If you're writing this as a shell function, then you don't need to eval.

The indentation could be done more idiomatically. By using elif, you can eliminate one level of indentation and make the code structure clearer.

up() {
 if [ -z "1ドル" ]; then 
 cd ..
 elif [ "1ドル" -eq "1ドル" ]; then
 if [ "1ドル" -lt 0 ]; then
 echo "First argument is not a positive integer"
 else
 for i in `seq 1 1ドル`; do
 cd ..
 done
 pwd
 fi
 else
 echo "First argument is not an integer"
 fi
}

Your question is very similar to this one this one. The main problem, as you have already noted in your own comment, is that by doing multiple cd .. in sequence instead of one cd ../../.., you would be inserting many hops into the directory history. Then, cd - or referencing $OLDPWD wouldn't work as expected.

If you're writing this as a shell function, then you don't need to eval.

The indentation could be done more idiomatically. By using elif, you can eliminate one level of indentation and make the code structure clearer.

up() {
 if [ -z "1ドル" ]; then 
 cd ..
 elif [ "1ドル" -eq "1ドル" ]; then
 if [ "1ドル" -lt 0 ]; then
 echo "First argument is not a positive integer"
 else
 for i in `seq 1 1ドル`; do
 cd ..
 done
 pwd
 fi
 else
 echo "First argument is not an integer"
 fi
}

Your question is very similar to this one. The main problem, as you have already noted in your own comment, is that by doing multiple cd .. in sequence instead of one cd ../../.., you would be inserting many hops into the directory history. Then, cd - or referencing $OLDPWD wouldn't work as expected.

If you're writing this as a shell function, then you don't need to eval.

The indentation could be done more idiomatically. By using elif, you can eliminate one level of indentation and make the code structure clearer.

up() {
 if [ -z "1ドル" ]; then 
 cd ..
 elif [ "1ドル" -eq "1ドル" ]; then
 if [ "1ドル" -lt 0 ]; then
 echo "First argument is not a positive integer"
 else
 for i in `seq 1 1ドル`; do
 cd ..
 done
 pwd
 fi
 else
 echo "First argument is not an integer"
 fi
}

Your question is very similar to this one. The main problem, as you have already noted in your own comment, is that by doing multiple cd .. in sequence instead of one cd ../../.., you would be inserting many hops into the directory history. Then, cd - or referencing $OLDPWD wouldn't work as expected.

Restructure if-elses
Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479

If you're writing this as a shell function, then you don't need to eval.

The indentation could be done more idiomatically. By using elif, you can eliminate one level of indentation and make the code structure clearer.

up() {
 if [ -z "1ドル" ]; then 
 cd ..
 elif [ "1ドル" -eq "1ドル" ]; then
 if [ "1ドル" -gtlt "0"0 ]; then
 forecho i"First inargument `seqis 1not 1ドル`;a do
positive integer"
 else
 cd ..
 for i in `seq 1 1ドル`; do
 done
 pwd
 cd ..
 else
 done
 echo "First argument is not a positive integer"pwd
 fi
 else
 echo "First argument is not an integer"
 fi
}

Your question is very similar to this one. The main problem, as you have already noted in your own comment, is that by doing multiple cd .. in sequence instead of one cd ../../.., you would be inserting many hops into the directory history. Then, cd - or referencing $OLDPWD wouldn't work as expected.

If you're writing this as a shell function, then you don't need to eval.

The indentation could be done more idiomatically. By using elif, you can eliminate one level of indentation and make the code structure clearer.

up() {
 if [ -z "1ドル" ]; then 
 cd ..
 elif [ "1ドル" -eq "1ドル" ]; then
 if [ "1ドル" -gt "0" ]; then
 for i in `seq 1 1ドル`; do
 cd ..
 done
 pwd
 else
 echo "First argument is not a positive integer"
 fi
 else
 echo "First argument is not an integer"
 fi
}

Your question is very similar to this one. The main problem, as you have already noted in your own comment, is that by doing multiple cd .. in sequence instead of one cd ../../.., you would be inserting many hops into the directory history. Then, cd - or referencing $OLDPWD wouldn't work as expected.

If you're writing this as a shell function, then you don't need to eval.

The indentation could be done more idiomatically. By using elif, you can eliminate one level of indentation and make the code structure clearer.

up() {
 if [ -z "1ドル" ]; then 
 cd ..
 elif [ "1ドル" -eq "1ドル" ]; then
 if [ "1ドル" -lt 0 ]; then
 echo "First argument is not a positive integer"
 else
 for i in `seq 1 1ドル`; do
 cd ..
 done
 pwd
 fi
 else
 echo "First argument is not an integer"
 fi
}

Your question is very similar to this one. The main problem, as you have already noted in your own comment, is that by doing multiple cd .. in sequence instead of one cd ../../.., you would be inserting many hops into the directory history. Then, cd - or referencing $OLDPWD wouldn't work as expected.

Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479

If you're writing this as a shell function, then you don't need to eval.

The indentation could be done more idiomatically. By using elif, you can eliminate one level of indentation and make the code structure clearer.

up() {
 if [ -z "1ドル" ]; then 
 cd ..
 elif [ "1ドル" -eq "1ドル" ]; then
 if [ "1ドル" -gt "0" ]; then
 for i in `seq 1 1ドル`; do
 cd ..
 done
 pwd
 else
 echo "First argument is not a positive integer"
 fi
 else
 echo "First argument is not an integer"
 fi
}

Your question is very similar to this one. The main problem, as you have already noted in your own comment, is that by doing multiple cd .. in sequence instead of one cd ../../.., you would be inserting many hops into the directory history. Then, cd - or referencing $OLDPWD wouldn't work as expected.

lang-bash

AltStyle によって変換されたページ (->オリジナル) /