Sponsored Content
Full Discussion: Add spaces to variable
Top Forums UNIX for Dummies Questions & Answers Add spaces to variable Post 302958872 by RudiC on Tuesday 27th of October 2015 04:57:33 AM
Old 10-27-2015
NewName has the value " 12". Print it within double quotes:
Code:
N=$(printf "%*s" 3 $1)
echo $N
12
echo "$N"
 12

Please note there's a double quote missing in your assignment...
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies

2. Shell Programming and Scripting

Variable containing spaces

Hi, my var is: PATH_LOG=/opt/WebSphere/CR Comune Roma.log a filename which contains blank chars. How can I call it from prompt ? Ex: ls $PATH_LOG or cat $PATH_LOG tks, Carmen- (2 Replies)
Discussion started by: Carmen123
2 Replies

3. Shell Programming and Scripting

appending spaces to a variable

Hi All, I have a requirement, in which i have to append some spaces to the variable, and then send it to another function. I am new to the UNIX shell programming. Ultimately the length of the string should be 40 characters. exp: Login = "rallapalli" (length = 10) i have to append 30 spaces to... (2 Replies)
Discussion started by: rallapalli
2 Replies

4. Shell Programming and Scripting

adding spaces for a variable value

Hi, i have to form the header and add fillers(spaces) to it. I have done something like this. i have added 10 spaces at the end HDR="AAAABBBBCCNN " echo $HDR >> file1.dat but the spaces are not being stored in the file. How to add the spaces. (2 Replies)
Discussion started by: dnat
2 Replies

5. Shell Programming and Scripting

Triming spaces for any variable

Hi, I want to trim the spaces on left side of the variable value. For eg: if it is 4 spaces followed by value, All the spaces on the left should be supressed. Easy but want it quickly. Regards, Shiv@jad (6 Replies)
Discussion started by: Shiv@jad
6 Replies

6. Shell Programming and Scripting

Spaces in a rsync variable

The following code doesn't work because of the space in "My Documents". Is there a way to set the "sources" variable and then use it in rsync? I tried escape space (\ ) and quotes, but nothing worked. #!/bin/sh sources="'/home/wolf' '/media/sda1/Documents and Settings/Administrator/My... (5 Replies)
Discussion started by: wolfv
5 Replies

7. Shell Programming and Scripting

Variable with several values and spaces.

Hello all. I am a newb obviously and a bit stumped on this, so any help gratefully accepted. The script is extracting metadata from individual mp3 files, then (hopefully will be) sorting them into newly-created subdirectories. I have filtered out the relevant metadata and have the album names... (8 Replies)
Discussion started by: spoovy
8 Replies

8. Shell Programming and Scripting

The last argument contains spaces, how do I get it into a variable?

Gooday I have an argument string that contains 15 arguments. The first 14 arguments are easy to handle because they are separated by spaces ARG14=`echo ${ARGSTRING} | awk '{print $14}'` The last argument is a text that may be empty or contain spaces. So any ideas on how I get the last... (23 Replies)
Discussion started by: zagga
23 Replies

9. Shell Programming and Scripting

Trimming spaces from a variable

Hi guys, when I take substring of a particular data using this command var=substr($0,11,10) it comes with spaces, when I am trying to trim the spaces it is not allowing me to do that. Can you please help me out on that. As I have to reverse the output of the variable also. ---------- Post... (0 Replies)
Discussion started by: manish8484
0 Replies

10. UNIX for Dummies Questions & Answers

Want to add trailing spaces to the variable

I want to keep string/varible length to 10 even its actual length is less than 10(may be no value). so, i want to add trailing spaces to my string. :wall: "typeset -L10 myvarible" is not working, its saying invalid typset -L option. Can you please advise. (4 Replies)
Discussion started by: djaks111
4 Replies
atof(3) 						     Library Functions Manual							   atof(3)

Name
       atof, atoi, atol, strtol, strtoul, strtod - convert ASCII to numbers

Syntax
       #include <math.h>

       double atof(nptr)
       char *nptr;

       atoi(nptr)
       char *nptr;

       long atol(nptr)
       char *nptr;

       long strtol(nptr, eptr, base)
       char *nptr, **eptr;
       int base;

       unsigned long strtoul(nptr, eptr, base)
       char *nptr, **eptr;
       int base;

       double strtod (nptr, eptr)
       char *nptr, **eptr;

       unsigned long strtoul(nptr, eptr, base)
       char *nptr, **eptr;
       int base;

Description
       These functions convert a string pointed to by nptr to floating, integer, and long integer representation respectively.	The first unrecog-
       nized character ends the string.

       The function recognizes (in order), an optional string of spaces, an optional sign, a string of digits optionally containing a radix  char-
       acter, an optional `e' or `E', and then an optionally signed integer.

       The and functions recognize (in order), an optional string of spaces, an optional sign, then a string of digits.

       The  function returns as a long integer, the value represented by the character string nstr.  The string is scanned up to the first charac-
       ter inconsistent with the base.	Leading white-space characters are ignored.

       If the value of eptr is not (char **) NULL, a pointer to the character terminating the scan is returned in **eptr.  If no  integer  can	be
       formed, **eptr is set to nstr , and zero is returned.

       If  base  is  positive  and  not greater than 36, it is used as the base for conversion.  After an optional leading sign, leading zeros are
       ignored, and 0x or 0X is ignored if base is 16.

       If base is zero, the string itself determines the base thus:  After an optional leading sign, a leading zero  indicates	octal  conversion,
       and a leading 0x or 0X hexadecimal conversion.  Otherwise, decimal conversion is used.

       Truncation from long to int can take place upon assignment, or by an explicit cast.

       The function is the same as except that returns, as an unsigned long integer, the value represented by the character string nstr.

       The  function  returns  as a double-precision floating point number, the value represented by the character string pointed to by nptr.  The
       string is scanned up to the first unrecognized character.

       The function recognizes an optional string of white-space characters, as defined by isspace in then an optional sign, then a string of dig-
       its optionally containing a radix character, then an optional e or E followed by an optional sign or space, followed by an integer.

       If  the value of eptr is not (char **)NULL, a pointer to the character terminating the scan is returned in the location pointed to by eptr.
       If no number can be formed, *eptr is set to nptr, and zero is returned.

       The radix character for and is that defined by the last successful call to category If category has not been called successfully, or if the
       radix character is not defined for a supported language, the radix character is defined as a period (.).

   International Environment
       LC_CTYPE       If this environment variable is set and valid, uses the international language database named in the definition to determine
		      character classification rules.

       LC_NUMERIC     If this environment is set and valid, and use the international language database named in the definition to determine radix
		      character rules.

       LANG	      If  this environment variable is set and valid and use the international language database named in the definition to deter-
		      mine collation and character classification rules.  If or is defined, their definition supercedes the definition of LANG.

Diagnostics
       The function returns HUGE if an overflow occurs, and  a 0 value if an underflow occurs, and sets errno to ERANGE.  HUGE is defined in

       The function returns INT_MAX or INT_MIN (according to the sign of the value) and sets errno to ERANGE, if the correct value is outside  the
       range of values that can be represented.

       The  function  returns  LONG_MAX or LONG_MIN (according to the sign of the value) and sets errno to ERANGE, if the correct value is outside
       the range of values that can be represented.

       The function returns LONG_MAX or LONG_MIN (according to the sign of the value) and sets errno to ERANGE, if the correct	value  is  outside
       the range of values that can be represented.

       The function returns ULONG_MAX and sets errno to ERANGE, if the correct value is outside the range of values that can be represented.

       The function returns HUGE (according to the sign of the value), and sets errno to ERANGE if the correct value would cause overflow.  A 0 is
       returned and errno is set to ERANGE if the correct value would cause underflow.

See Also
       ctype(3), setlocale(3), scanf(3s), environ(5int)

																	   atof(3)
All times are GMT -4. The time now is 09:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy