Sponsored Content
Top Forums Shell Programming and Scripting Logic to separate the first name in the file Post 302999437 by ricky-row on Tuesday 20th of June 2017 08:21:12 AM
Old 06-20-2017
I have made this function in script, I need to use the VAR in other way after the function, do you have any idea how to do that

if there are 10 files with *.rpm, I need to store the VAR values like abc, xy-z, etc.. in a new file. So, after this function I have to check for the file existence first, if not have to create a file named test.txt.
then inside the file
Code:
NAME = abc 
TYPE = txt

for all the 10 fiiles.
NOTE: if already the file is existing it can overwrite the same file but 11th file is added it should not delete the existing in the test.txt, it should be added at the end.

Code:
test()
{
  pushd packages &>/dev/null
  mkdir -p ../info
  for p in $(ls *.rpm 2>/dev/null);do
    VAR=($(echo $p| sed 's/-[0-9].*//';))
    if [ -e /info/$VAR.list} ]; then continue;fi
      rpm -qlp $p | sed -re 's/^/./' > /info/$VAR.list};;
    esac
  done
  popd &>/dev/null
}
test


Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
it makes it easier to read and preserves spaces for indenting or fixed-width data.

Last edited by rbatte1; 06-20-2017 at 10:47 AM.. Reason: Added CODE tags
 

We Also Found This Discussion For You

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies
CHSH(1)                                                            User Commands                                                           CHSH(1)

NAME
chsh - change login shell SYNOPSIS
chsh [options] [LOGIN] DESCRIPTION
The chsh command changes the user login shell. This determines the name of the user's initial login command. A normal user may only change the login shell for her own account; the superuser may change the login shell for any account. OPTIONS
The options which apply to the chsh command are: -h, --help Display help message and exit. -R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. -s, --shell SHELL The name of the user's new login shell. Setting this field to blank causes the system to select the default login shell. If the -s option is not selected, chsh operates in an interactive fashion, prompting the user with the current login shell. Enter the new value to change the shell, or leave the line blank to use the current one. The current shell is displayed between a pair of [ ] marks. NOTE
The only restriction placed on the login shell is that the command name must be listed in /etc/shells, unless the invoker is the superuser, and then any value may be added. An account with a restricted login shell may not change her login shell. For this reason, placing /bin/rsh in /etc/shells is discouraged since accidentally changing to a restricted shell would prevent the user from ever changing her login shell back to its original value. FILES
/etc/passwd User account information. /etc/shells List of valid login shells. /etc/login.defs Shadow password suite configuration. SEE ALSO
chfn(1), login.defs(5), passwd(5). shadow-utils 4.5 01/25/2018 CHSH(1)
All times are GMT -4. The time now is 08:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy