Sponsored Content
Top Forums Shell Programming and Scripting strcat equivalent in shell scripting Post 302270711 by ramen_noodle on Monday 22nd of December 2008 03:12:56 PM
Old 12-22-2008
Vgersh is very good at this type of problem and I don't want to but in, but most cases, in most shells, using an array to store the data and exploding the array is a simple way to form a concatenated string of disparate variables.

Short example with bash and gawk.
Code:
function retrandstr() {
gawk '
  function retrandchars(str, sz,rval,i) {
  sz = int(1 + rand() * length(str))
  i =0
        #print sz, i; 
         while (i < sz) {
                rval = rval substr(str,int((1 + rand() * length(str))),1); 
                i++;
          }
  return rval
  }
  BEGIN {
    srand();
    print retrandchars("abndhcv784893ndyvurfgh3ery348infy7478")
  }'
  sleep 1
}

Test--
while test "$i" -gt 0;  do arr[$i]=`retrandstr`; i=`expr $i - 1`;  done
list=${arr[@]}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

2. Programming

strcat() dumping core

strcat dumping core in the situation like main() { char* item; char* p=sat_item; char type; item=(char*) malloc(strlen(p)); strncpy(type,p,4); type='\0'; strcat(item,type); //dumping core } I couldn't get why strcat dumping core? (3 Replies)
Discussion started by: satish@123
3 Replies

3. Programming

`strcat' makes pointer from integer without a cast

A question to ask. seq1 = "eeeeeeeeeeeeeeeeee"; seq2 = "dddddddddddddddddddd"; char a = '*'; strcat(*seq2, &a); strcat(*seq1, seq2); compilation warning: passing arg 1 of `strcat' makes pointer from integer without a cast thanks (4 Replies)
Discussion started by: cdbug
4 Replies

4. Shell Programming and Scripting

shell script equivalent for tcl function

Hello, I need experts help in converting the below tcl function to korn shell function equivalent. proc lsNetMaskToBits {mask} { set dw ; # Top N bits set set dw 0x ; # Make sure it's hexadecimal, else XOR fails. puts "lsNetMaskToBits dw $dw" set dw ; # Complement => low 32-N bits... (1 Reply)
Discussion started by: JackMelson
1 Replies

5. Shell Programming and Scripting

Windows command shell equivalent in Unix

In Windows we use cmd.exe \c as the command SHell What is its equivalent in UNIX ? Thanx for all your help. (10 Replies)
Discussion started by: simonsimon
10 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Programming

strcat outputs garbage

Anyone have any ideas why when using strcat function I would get some garbage at the beginning of the output string? what I'm doing is something like the following example. Code: char temp; char tempHolder; for(int i=0;i<something;i++){ sprintf(temp,"%u ", someVariable);... (2 Replies)
Discussion started by: airon23bball
2 Replies

8. Programming

strcat in C

Hello, #include <stdio.h> #include <string.h> void main() { char tab={"12"}; FILE *outfile; char *outname = "/home/dir/"; printf("%s",strcat(outname,tab)); outfile = fopen(strcat(outname,tab), "w"); if (!outfile) { printf("There was a problem opening %s for writing\n", outname); ... (2 Replies)
Discussion started by: chercheur857
2 Replies

9. UNIX for Dummies Questions & Answers

Shell equivalent of matlab fwrite function

I have some matlab code that sends the serial port elements of an array using matlab's fwrite function, e.g.: fwrite(s, , 'uchar'); What would be a unix shell equivalent? E.g., after successfully accessing the port using instructions here: Simple terminal serial port program for Linux/MacOSX... (3 Replies)
Discussion started by: darwin_886
3 Replies

10. Shell Programming and Scripting

Equivalent to let command in POSIX shell

Hi all, I am learning POSIX shell programming, and the book I read, uses the let command for integer arithmetic. I have downloaded and use the shellcheck program on Linux. This programs says: In POSIX sh, 'let' is undefined. See the screenshot attached. What is the POSIX... (1 Reply)
Discussion started by: johnprogrammer
1 Replies
SOCKET_SET_OPTION(3)							 1						      SOCKET_SET_OPTION(3)

socket_set_option - Sets socket options for the socket

SYNOPSIS
bool socket_set_option (resource $socket, int $level, int $optname, mixed $optval) DESCRIPTION
The socket_set_option(3) function sets the option specified by the $optname parameter, at the specified protocol $level, to the value pointed to by the $optval parameter for the $socket. PARAMETERS
o $socket - A valid socket resource created with socket_create(3) or socket_accept(3). o $level - The $level parameter specifies the protocol level at which the option resides. For example, to retrieve options at the socket level, a $level parameter of SOL_SOCKET would be used. Other levels, such as TCP, can be used by specifying the protocol number of that level. Protocol numbers can be found by using the getprotobyname(3) function. o $optname - The available socket options are the same as those for the socket_get_option(3) function. o $optval - The option value. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 socket_set_option(3) example <?php $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!is_resource($socket)) { echo 'Unable to create socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) { echo 'Unable to set option on socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } if (!socket_bind($socket, '127.0.0.1', 1223)) { echo 'Unable to bind socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } $rval = socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR); if ($rval === false) { echo 'Unable to get socket option: '. socket_strerror(socket_last_error()) . PHP_EOL; } else if ($rval !== 0) { echo 'SO_REUSEADDR is set on socket !' . PHP_EOL; } ?> PHP Documentation Group SOCKET_SET_OPTION(3)
All times are GMT -4. The time now is 12:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy