Sponsored Content
Top Forums Shell Programming and Scripting Why the results of these two code fragments are not the same? Post 303030162 by johnprogrammer on Wednesday 6th of February 2019 08:41:52 PM
Old 02-06-2019
Why the results of these two POSIX shell code fragments, are not the same?

Code 1:

Code:
#!/bin/sh

for arg1 in "$@"
do
    counter=0

   for arg2 in "$@"
   do

     if [ "$arg2" = "$arg1" ] && [ $counter -eq 0 ]
     then
       counter=$((counter+1))

       continue 
    fi


   if [ "$arg2" = "$arg1" ]
   then
    
     echo
     echo "Error: Two or more arguments are the same."
     echo
     echo "Exiting..."
     echo

     exit 1
    fi

  done

done

exit 0

It outputs:
Code:
[john@manjaromatepc Downloads]$ ./script.sh ~/Documents/ ~/Downloads/
[john@manjaromatepc Downloads]$

Code 2:

Code:
#!/bin/sh


for arg1 in "$@"
do
  
  counter=0

  for arg2 in "$@"
  do


    if [ $counter -eq 0 ]
    then
  
      counter=$((counter+1))

      continue 
   fi


  if [ "$arg2" = "$arg1" ]
  then
    
    echo
    echo "Error: Two or more arguments are the same."
    echo
    echo "Exiting..."
    echo

    exit 1
  fi

 done

done

exit 0

It outpouts:

Code:
 
[john@manjaromatepc Downloads]$ ./script.sh ~/Documents/ ~/Downloads/

Error: Two or more arguments are the same.

Exiting...

[john@manjaromatepc Downloads]$


Last edited by johnprogrammer; 02-06-2019 at 10:49 PM.. Reason: The second code fragment has a logical mistake
 

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

fragments in Solaris 8

When discussing inodes and data blocks, I know Solaris creates these data blocks with a total size of 8192b, divided into eight 1024b "fragments." It stores data in "contiguous" fragments and solaris doesn't allow a file to use portions of two different fragments. If the file size permits, then the... (4 Replies)
Discussion started by: manderson19
4 Replies

2. Post Here to Contact Site Administrators and Moderators

results survey

Hi guys! I was wondering what the outcome was of your survey of a few months ago? One of the questions was if people were willing to pay for additional services like an own account, like username@unix.com with mail box, etc. Sorry if I missed the results if you had already posted them. Ivo (1 Reply)
Discussion started by: Ivo
1 Replies

3. Solaris

ipfilter blocking ip fragments

For some reason ipfilter is blocking inbound fragmented ip packets (the packets are larger than the interface's MTU) that are encapsulating UDP segments. The connection works, so I know ipfilter is letting some traffic through, it is just a lot slower than it should be. Rules that allow the... (3 Replies)
Discussion started by: ilikecows
3 Replies

4. IP Networking

Solaris 11 Express NAT/Router IP Fragments

Upon replacing my linux router/server with a Solaris one I've noticed very poor network performance. The server itself has no issues connecting to the net, but clients using the server as a router are getting a lot of IP fragments as indicated from some packet sniffing I conducted. Here was my... (3 Replies)
Discussion started by: vectox
3 Replies

5. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

6. Shell Programming and Scripting

Why use different FS, the results is different?

# echo '1 2 3 ' | awk -F' ' '{print NF}' 3 # echo '1:2:3:' | awk -F':' '{print NF}' 4 (1 Reply)
Discussion started by: lazycat79
1 Replies

7. Shell Programming and Scripting

Extract fragments from file

I have a .xml file that looks something like this : <measInfo> ......... string1 ......... </measInfo> <measInfo> ...... string2 ........ </measInfo> I want to extract only the 'chunk of file' from '<measInfo>' to '</measInfo>' containing string1 (or a certain string that I... (13 Replies)
Discussion started by: black_fender
13 Replies

8. Shell Programming and Scripting

I want to add a variable for the results from the formula of one variable and results of another var

Good morning all, This is the file name in question OD_Orders_2019-02-19.csv I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies
FSSYNC-DEBUG_STATS(8)					       AFS Command Reference					     FSSYNC-DEBUG_STATS(8)

NAME
fssync-debug_stats - Displays various statistics SYNOPSIS
fssync-debug stats -cmd <subcommand> [-arg1 <arg1>] [-arg2 <arg2>] [-reason <sync protocol reason code>] [-programtype <program type code>] [-help] fssync-debug s -c <subcommand> [-arg1 <arg1>] [-arg2 <arg2>] [-r <sync protocol reason code>] [-p <program type code>] [-h] DESCRIPTION
The fssync-debug stats command displays statistics according to the value of the option -cmd. OPTIONS
-cmd <subcommand> Specifies statistics subcommand. Available subcommands are: o pkg -- general volume package statistics o vicep -- vice partition statistics o hash -- volume hash chain statistics o hdr -- volume header cache statistics o vlru -- vlru generation statistics o help -- display list of available subcommands -arg1 <arg1> Specifies first optional argument, in the context of the chosen subcommand. For vicep statistics, it specifies partition name; for hash statistics, it specifies hash bucket number; for vlru statistics it specifies vlru generation number. -arg2 <arg2> Specifies second optional argument, in the context of the chose subcommand. Currently, none of the subcommands use it. -reason <sync protocol reason code> Specifies numeric sync protocol reason code. Available codes are listed in OpenAFS source file src/vol/fssync_inline.h. For SYNC_REASON_NONE, use -reason 0. -programtype <program type code> Specifies program type code. Permitted values are fileServer, volumeUtility, salvager, salvageServer, volumeServer and volumeSalvager. PRIVILEGE REQUIRED
The issuer must have write access to the file server. Usually, this means that the issuer must be the local superuser "root" on the file server machine. SEE ALSO
fssync-debug_header(8), fssync-debug_query(8) COPYRIGHT
Copyright 2010 Davor Ocelic <docelic@spinlocksolutions.com> This documentation is covered by the IBM Public License Version 1.0. This man page was written by Davor Ocelic for OpenAFS, based on documentation from Steven Jenkins, Tom Keiser and Simon Wilkinson. OpenAFS 2012-03-26 FSSYNC-DEBUG_STATS(8)
All times are GMT -4. The time now is 01:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy