Change existing variable value only user enters non-empty string.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change existing variable value only user enters non-empty string.
# 8  
Old 05-20-2010
Kchinnam, you are seeing the newlines ('\n") in your od output because you are using the echo command to pipe the variable in question to od. The echo command adds a newline to its output by design.

Try the following example
Code:
uid="scott"
echo "${uid}" |  od -bcx
printf "${uid}" |  od -bcx

gid=
echo "${gid}" |  od -bcx
printf "${gid}" |  od -bcx

Here is the output from this example
Code:
$ ./example
0000000  163 143 157 164 164 012
           s   c   o   t   t  \n
            6373    746f    0a74
0000006
0000000  163 143 157 164 164
           s   c   o   t   t
            6373    746f    0074
0000005
0000000  012
          \n
            000a
0000001
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change date time stamp of existing file

I have a file hello.txt which was created today (today's date timestamp) I wish to change its date timestamp (access, modified, created) to 1 week old i.e one week from now. uname -a SunOS mymac 5.11 11.2 sun4v sparc sun4v Can you please suggest a easy way to do that ? (12 Replies)
Discussion started by: mohtashims
12 Replies

2. Shell Programming and Scripting

Script stops running after assigning empty string for a variable

Hi, This is the first time I see something like this, and I don't why it happens. Please give me some help. I am really appreciate it. Basically I am trying to remove all empty lines of an input.. #!/bin/bash set -e set -x str1=`echo -e "\nhaha" | grep -v ^$` #str2=`echo -e "\n" |... (4 Replies)
Discussion started by: yoyomano
4 Replies

3. Shell Programming and Scripting

How do I change a variable to something only if it's empty?

I feel like it is just a matter of using the $ operators correctly, but I can't seem to get it... hostname="network" ip="192.168.1.1" netmask="" variables=( $hostname $ip $netmask ) for var in ${variables} do if ; then $var="--" fi done echo... (7 Replies)
Discussion started by: etranman1
7 Replies

4. Shell Programming and Scripting

How to change last character in string with a variable value.

Hey Guys, I have text such as this. 28003,ALCORN,2 28009,BENTON,2 28013,CALHOUN,2 28017,CHICKASAW,2 47017,CARROLL,2 05021,CLAY,0 The last digit after the final "," is a variable value. This is the base file. I have to do further execution on this file later and I need to update the... (7 Replies)
Discussion started by: chagan02
7 Replies

5. Shell Programming and Scripting

awk: change string variable

Hi. How to change string variable in awk? for example, I parse with awk script text file named some_name_with_extension.txt I want to print only some_name in my script .... varCompName = FILENAME print varCompName How to put not all symbols from FILENAME to variable? thank you This... (4 Replies)
Discussion started by: cintlt
4 Replies

6. Shell Programming and Scripting

BASH - set specific user variable via string operators

Apologies for the utter triviality of this question, but we all have to start somewhere! I've also tried searching but this question is pretty vague so I didn't (a) really know what to search for or (b) get many relevant hits to what I did search for. Anyway, I'm in the process of self-teaching... (1 Reply)
Discussion started by: u5j84
1 Replies

7. Solaris

Add existing user into an existing group

Pre: no gpasswd/adduser there is just usermod can be used, also there is no -a option for usermod. How should I add a user into a group? (4 Replies)
Discussion started by: a2156z
4 Replies

8. UNIX for Dummies Questions & Answers

New Variable with Existing variable( Urgent)

hi all, i want use the variable value as a new variable name. print output of new variable. for i in COMPUTER1 COMPUTER2 do flag_name=${i}_FLAG eval ${flag_name}=123 echo $i'_FLAG' done output is COMPUTER1_FLAG COMPUTER2_FLAG i need output as 123 123 (2 Replies)
Discussion started by: arvindng
2 Replies

9. UNIX for Dummies Questions & Answers

how can i change the date of an existing file

Hi, Plz suggest me how can i change the date of a file. Suppose my file has been created in some date and i want to give it present date. How can i do this???? (2 Replies)
Discussion started by: adityam
2 Replies

10. Shell Programming and Scripting

if test for empty and non-existing file

How to write this condition in ksh? if myfile is empty or myfile does not exist then do action1 fi is this OK? if ] -o ] then then do action1 fi Thanks. (3 Replies)
Discussion started by: GNMIKE
3 Replies
Login or Register to Ask a Question
lusermod(8)						      System Manager's Manual						       lusermod(8)

NAME
lusermod - Modify an user SYNOPSIS
lusermod [OPTION]... user DESCRIPTION
Modifies the user with name user. OPTIONS
-c, --gecos=gecos Set user's GECOS field to gecos. The GECOS field is traditionally used to store user's real name and other information. -d, --directory=directory Set user's home directory to directory. -g, --gid=gid Change user's primary group ID to gid. If group with ID gid does not exist, a warning is printed, but the operation is performed anyway. -i, --interactive Ask all questions when connecting to the user database, even if default answers are set up in libuser configuration. -L, --lock Lock user's account. This prevents logging in using user's password. -l, --login=name Rename user to name. -m, --movedirectory After changing user's home directory (using the -d option), move the old home directory to the new location. -P, --plainpassword=password Set user's password to password. Note that the password can be viewed while running lusermod using tools such as ps(1). -p, --password=encrypted Set user's password to the password represented by the hash encrypted. Note that the hash can be viewed while running lusermod using tools such as ps(1). -s, --shell=shell Set user's login shell to shell. -U, --unlock Unlock user's account. -u, --uid=uid Change user's user ID to uid. EXIT STATUS
The exit status is 0 on success, nonzero on error. libuser Feb 27 2008 lusermod(8)